-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Proposal] Compute cursor for each document #156
Comments
Let me know your thoughts on this. If this seems ok, don't mind opening a PR for this. |
Interesting and could be useful. Would this be a replacement for the current API? What are the advantages of having _cursors on each result? |
I don't foresee it to be a replacement, more like an addition to the existing. Can be optionally enabled by adding another param say |
Yes, sounds useful. I'd accept a PR. Perhaps for now make it an option? |
1 similar comment
Yes, sounds useful. I'd accept a PR. Perhaps for now make it an option? |
Also, interest in, relay is very opinionated in terms of data structure that's why @simararneja is talking about cursor per document. Relay is driving pagination spec for Graphql, a lot of services take it as "best practice". Having the ability to use document cursor would help to implement relay compliant webservers |
Also is there any way to get the total count instead of HasNext ? I can mimic that by running |
This library doesn't provide a way to get a total count. I don't think we'd want that - even if it was opt-in-only - given the performance cost of running such query. |
Any updates on this? |
Forked the project to create a PR for this, but |
For a project of mine we're sorting by the @bradvogel any tips on how to re-use some internal functions to implement it in a generic way? |
I'm implementing a POC based on this logic: First I implemented a generic cursor builder function: My guess is that in future we could replace that first logic with this function: Or maybe removing these if's at all, using the cursors already computed for the first and last result: What do you think about this approach @bradvogel? I still got no chance to test it because of the |
Thanks for letting us know about the issue npm installing. That should now be fixed. Can you share more about what you're trying to do? Are you putting a cursor on each document returned? |
@bradvogel thanks, I don't think putting a cursor on each document returned would be the best approach, that could introduce some hard to debug issues, but I think it's a good starting point as a prototype to show it working. The optimal approach would be instead of returning an array of documents, return an array of results which each result would include the document and some metadata, including the cursor.
That's the approach seen in Relay Connections specification, so a good slice of the community would be already familiar with it. The cursor of course would be the first metadata, but I can imagine it growing in the future with other requirements like a Another valid approach would be returning a separated array of cursors, where the relationship would be maintained with the indexes of the documents on the result:
I see some friction with the developer experience here, but this approach would be backwards compatible and wouldn't mix the cursor with the document fields. I'm looking forward to discuss the options here, I would love to see other's considerations about each approach:
|
I'm trying to run the tests, but when I run I do have a freshly intalled MongoDB instance runing on my machine available at localhost on the default port, as pointed in the readme. |
Added the POC of this feature, waiting for guidance on which approach to take on this feature. |
Re: mongodb installing when running
Perhaps Re: adding _cursor to each document. Looks like a useful feature. Perhaps make it opt-in via a parameter so we don't need to change the API? |
Pushed some updates in my PR to include the
|
Feature request & proposal
Highlighting the relay specification for the cursor based pagination which specifies a cursor for each document. As things are today, this library returns pagination metadata as separate fields (
next
,previous
, etc..) which points to the last document of the list.I propose to add an additional field
_cursor
for each document which will allow the user to move in forward/backward direction from any node in a list.Example -
The text was updated successfully, but these errors were encountered: