zid
zid11mo ago

The InvalidCursor error happens if the query's index range changes between requests

Wanting to confirm something. The InvalidCursor error ( InvalidCursor: Tried to run a query starting from a cursor, but it looks like this cursor is from a different query.) happens if the query's index range changes between requests, and thus it is not possible/viable to setup multiple query definitions/statements if (x) query.withIndex(by_1), else if(y) withIndex(by_2) inside a single query function? Is the best/only way then to separate each query into its own query function?
4 Replies
erquhart
erquhart11mo ago
Yeah, I've run into this. You only want one paginated db call per query. The cursors aren't interchangeable between ctx.db.query calls.
Michal Srb
Michal Srb11mo ago
If you can use separate paginated queries, then great. If not, you can implement the pagination yourself, like I did here: https://github.com/xixixao/convex-ents/blob/main/src/deletion.ts#L356-L363
GitHub
convex-ents/src/deletion.ts at main · xixixao/convex-ents
Contribute to xixixao/convex-ents development by creating an account on GitHub.
zid
zidOP11mo ago
thank you Michal. That's interesting! from what i can tell at a glance youre controlling the num of items read from a table; not sure about the bytes part however. Regardless i'll takea serious look this evening thank you! Got it, most likely i'll separate this into its own fns, at least write a hook to encapsulate all the permutations just wanted to note this is a great example (just had a chance to review), thank you for sharing!
RJ
RJ11mo ago
This is a helpful example to have! Does this account for the possibility that multiple documents have equivalent _creationTimes?

Did you find this page helpful?