Using sort with fetchObjects in JS/TS Client v3 not working

I am using the Weaviate JS/TS Client v3 and trying to fetch objects from a collection with sorting. My code looks like this:

const offset = page * limit;
const queryOptions = {
  filters: filters,
  limit: limit,
  offset: offset,
  returnProperties: ["name"],
  sort: [
    {
      path: ["name"],
      order: "asc",
    },
  ],
};
const result = await collection.query.fetchObjects(queryOptions);

When I run this, I get the following error:

Cannot read properties of undefined (reading 'map')

  • I am not using any search operators (like nearText or nearVector), just fetchObjects.

  • The error seems to be related to the use of the sort option because if I remove it, works fine

What could be causing this error? Is there something wrong with my usage of the sort parameter, or could this be a bug in the client?

Any help would be appreciated. Thanks :slight_smile:

Hi @MELINA_BELEN_JAUREGU ,

Good Day!

Welcome to Weaviate Community!

May I know if this issue is persistent or an intermittent issue? Are you also using Weaviate Cloud for your cluster?

Hi!
This is the first time I tried to use this feature, so I can not tell if it did work previously.

And yes, I am currently using Weaviate cloud.

Thanks @MELINA_BELEN_JAUREGU as checked looks like sort function is not yet supported with JS client v3 will clarify this internally.

For the meantime, you can try using GraphQL for sorting: Additional operators | Weaviate Documentation

Good morning Melina,

Adding to what my colleague @maryannc mentioned, if you’re using a cloud cluster, it’s always best to open a ticket with us at support@weaviate.io. That’s our ticketing system for cloud users and customers, covered under SLA, and it’s fast way to get support as well :upside_down_face:.

If you could open a ticket, we can investigate why sorting isn’t yet mapped in JS/TS v3. I believe this should already be implemented. We can run a check with our client engineering.

In the meantime, as @maryannc mentioned, GraphQL can be used as an alternative.

Best regards,

Mohamed Shahin
Weaviate Support Engineer
(Ireland, UTC±00:00/+01:00)

1 Like

Hi @MELINA_BELEN_JAUREGU ,
As confirmed with our core engineering team, sorting is already supported in JS/TS client v3. However, the documentation has not yet been updated to reflect this. We’ve raised the issue, and the documentation will be updated in the coming weeks.

In the meantime, here’s the new syntax for using sorting in v3:

c.query.fetchObjects({
  sort: collection.sort.byProperty('name')
})

You can use this approach, or alternatively, continue using GraphQL if preferred.

Hope this helps! Let us know if you have any further questions.

2 Likes