RJR
Convex Community3y ago
20 replies
RJ

How to filter by indexed field and order by creation time?

Let's say I have a schema with a table like this:

dogs: defineTable({
  owner: s.id("people"),
}).index("by_owner", ["owner"]),


And I want to write a query which returns for me a list of all of the dogs owned by a particular person, sorted with the newest dogs at the front (meaning sorted by _creationTime descending). How would I accomplish that?

Both

db
  .query("dogs")
  .withIndex("by_owner", (q) =>
    q.eq("owner", ownerId))
  )
  .order("desc")


and


db
  .query("dogs")
  .withIndex("by_owner", (q) =>
    q.eq("owner", ownerId))
  )
  .order("asc")


seem to return the same result, which makes me think, as perhaps stated in support-communityorder by, that order is sorting only ownerId.
Was this page helpful?