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 option to use returnDocument #41

Closed
wants to merge 1 commit into from

Conversation

alecgibson
Copy link

@alecgibson alecgibson commented Jun 29, 2021

Fixes #38

The mongodb Node.js driver deprecated use of returnOriginal in
favour of returnDocument in v3.6.

This non-breaking change allows consumers to opt in to using the newer
returnDocument by setting an option on construction

var queue = mongoDbQueue(db, 'queue', { returnDocument : true })

mongodb-queue.js Outdated Show resolved Hide resolved
mongodb-queue.js Outdated
@@ -266,3 +273,12 @@ Queue.prototype.done = function(callback) {
callback(null, count)
})
}

Queue.prototype._optionsWithNewDocument = function(query) {

Choose a reason for hiding this comment

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

Maybe renaming the function to getDefaultQueryOptions might improve readability

Copy link
Author

@alecgibson alecgibson Jun 29, 2021

Choose a reason for hiding this comment

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

It's not quite what this function does: it actually adds the "return a new document" flag (whatever that is) to the passed set of options.

If we had access to the spread operator you could do something like:

var options = {
  // other options here
  ...self._returnNewDocument(),
}

...but we can't really do that without a transpiler I think.

Copy link
Author

@alecgibson alecgibson Jun 29, 2021

Choose a reason for hiding this comment

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

Could just call it _returnOriginal() anyway. Probably just as meaningful with fewer words:

var options = self._returnNewDocument({
  // other options
})

Choose a reason for hiding this comment

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

So I got a question, sorry for my ignorence, but why don't you just replace the flag and discard the previous/deprecated option?

If the usage is deprecated, just replace it ?

Copy link
Author

Choose a reason for hiding this comment

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

To avoid making this a breaking change — it would break any clients who are using older versions of mongodb.

The `mongodb` Node.js driver deprecated use of `returnOriginal` in
favour of `returnDocument` in [v3.6][1].

This non-breaking change allows consumers to opt in to using the newer
`returnDocument` by setting an option on construction

```js
var queue = mongoDbQueue(db, 'queue', { returnDocument : true })
```

[1]: mongodb/node-mongodb-native#2808
@alecgibson alecgibson closed this Mar 2, 2023
@alecgibson alecgibson deleted the return-document-option branch March 2, 2023 11:47
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.

returnOriginal flag is deprecated in findOneAndUpdate
2 participants