question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature Proposal] Compute cursor for each document

See original GitHub issue

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 -


{
 "results":
   [ 
      { 
        " _id" : "580fd16aca2a6b271562d8bb", 
        "counter": 4, 
        "_cursor": "eyIkb2lkIjoiNTgwZmQxNmFjYTJhNmIyNzE1NjJkOGJiIn0" },
      {
       " _id": "580fd16aca2a6b271562d8ba",
       "counter": 3, 
        "_cursor": "eyIkb2lkIjoiNTgwZmQxNmFjYTJhNmIyNzE1NjJkOGJhIn0" 
      } 
  ],
  "next": "eyIkb2lkIjoiNTgwZmQxNmFjYTJhNmIyNzE1NjJkOGJhIn0",
  "hasNext": "true" 
}

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:18 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
bradvogelcommented, May 9, 2020

Also is there any way to get the total count instead of HasNext ? I can mimic that by running countDocuments with the query before the Mongo query but maybe you have another suggestion ? 😃

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.

1reaction
bradvogelcommented, Apr 23, 2020

Yes, sounds useful. I’d accept a PR. Perhaps for now make it an option?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues · mixmaxhq/mongo-cursor-pagination - GitHub
Contribute to mixmaxhq/mongo-cursor-pagination development by creating an account on GitHub. ... [Feature Proposal] Compute cursor for each document.
Read more >
cursor.forEach() — MongoDB Manual
Iterates the cursor to apply a JavaScript function to each document from the cursor. The forEach() method has the following prototype form: db.collection....
Read more >
cursor – Tools for iterating over MongoDB query results
Cursor class to iterate over Mongo query results. ... The tailable cursor type. Tailable cursors are only for use with capped collections. They...
Read more >
15 Improving Real-World Performance Through Cursor Sharing
The adaptive cursor sharing feature enables a single statement that contains bind variables to use multiple execution plans. Cursor sharing is "adaptive" ...
Read more >
Performance and Resource Utilization - Amazon DocumentDB
How Do I Find and Terminate Long Running or Blocked Queries? How Can I See a Query Plan and Optimize a Query? How...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found