How can I query a count of messages with particular fields when there could be 100s.
Otherwise it would time out if i try to query many messages with .collect().
4 Replies
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 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!
hey, as you have suggested in your code above, the way to effeciently query in convex is to use an index.
If you want to query a count you might want to checkout this component: https://www.convex.dev/components/aggregate or this one to help you with that: https://www.convex.dev/components/sharded-counter
@mikeysee in TS, the function count doesn't in OrderedQuery, only in QueryInitializer https://github.com/get-convex/convex-backend/blob/4583592bf0d996b7e03215ab2a32c329138cf070/npm-packages/convex/src/server/query.ts#L103
GitHub
convex-backend/npm-packages/convex/src/server/query.ts at 4583592bf...
The open-source reactive database for app developers - get-convex/convex-backend