Skip to content
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

add rewind function to QueryCursor #12710

Merged
merged 2 commits into from Nov 21, 2022

Conversation

passabilities
Copy link
Contributor

Summary

Wraps the mongodb.FindCursor.rewind function to reset the cursor to its uninitialized state, effectively resetting the cursor to the beginning.

Examples

const options = {}
ModelClass.find(options) 
// - instance1
// - instance2
// - instance3

// ================================================

const cursor = ModelClass.findOne(options).cursor()
await cursor.next() // instance1
await cursor.next() // instance2

cursor.rewind()
await cursor.next() // instance1

Wraps the `mongodb.FindCursor.rewind` function to reset the cursor to its uninitialized state, effectively resetting the cursor to the beginning.
*/

QueryCursor.prototype.rewind = function() {
this.cursor.rewind();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrap this in _waitForCursor(), because this.cursor can be undefined until async pre hooks run. Look at addCursorFlag for an example

@vkarpov15 vkarpov15 changed the base branch from master to 6.8 November 21, 2022 17:27
@vkarpov15 vkarpov15 added this to the 6.8 milestone Nov 21, 2022
Copy link
Collaborator

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, merging this into 6.8 branch

@vkarpov15 vkarpov15 merged commit b836ebc into Automattic:6.8 Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants