#[ents] filter by index with a field and order by "updatedAt" instead of "_creation_time"
14 messages · Page 1 of 1 (latest)
Thanks for posting in #1088161997662724167.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use [search.convex.dev](https://search.convex.dev) to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's #1228095053885476985 channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
here's a snippet
when i add a field, updatedAt, like this, function deployed
i get this error runtime error
*ignore the function path, the error is when i add the updatedAt field on the order
You make a new index with organizationId, and updatedAt so then its .table('mainList', 'organizationId_updatedAt', (q) => q.eq(...
Order only accepts asc or desc so its based on the last item in the index. And having a additional .eq/.gt for updatedAt is optional
hi @shrewd mica can you further explain? I think youre solution might work but I have no idea how it would look like and how do i get the sorted mainList based on updatedAt.
mainlist: defineEnt({})
.field('organizationId', v.string())
.field('updatedAt', v.number())
.index('organizationId_updatedAt', ['organizationId', 'updatedAt']),
const query = await ctx.table('mainList', 'organizationId_updatedAt', (q) => q.eq('organizationId', organizationId)).order('desc')
hey @shrewd mica this works!, thanks so much, yet i have no idea how indexing works like this.
Would you mind sharing some document/article explaining this.
This is a popular reference https://stack.convex.dev/databases-are-spreadsheets and then https://docs.convex.dev/database/indexes/