-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Fix 6940 add aliases for doc.delete and doc.updateOne #6953
Conversation
lib/document.js
Outdated
@@ -555,9 +555,15 @@ function init(self, obj, doc, prefix) { | |||
Document.prototype.update = function update() { | |||
const args = utils.args(arguments); | |||
args.unshift({_id: this._id}); | |||
return this.constructor.update.apply(this.constructor, args); | |||
return this.constructor.updateOne.apply(this.constructor, args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the interest of keeping the API consistent, let's make this still call update()
but make a separate Document.prototype.updateOne()
. As specified in this docs commit, there are a couple meaningful differences between update()
and updateOne()
:
- MongoDB version compatibility. Mongoose 5.x still supports MongoDB 3.0.x, but
updateOne()
requires MongoDB 3.2. update()
supports theoverwrite
option,updateOne()
does not.
We should also add a Document.prototype.replaceOne()
analogous to updateOne()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vkarpov15 But in a single document, the condition will always be _id
of the document. So it should be always update this single document
aka updateOne
. I think it's good to keep API consistent but adding updateOne
may be a little bit confusing? Just my opinion though.
Re: compatibility issue: mongodb@3.1
driver is actually calling update
internally for updateOne
operation. Even if developers are still running MongoDB Server 3.0.x, they can call updateOne
without any issue. Furthermore, current node-mongodb-native driver 3.1 is still marked as supporting MongoDB 2.6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Fonger good call, but that still leaves the issue with the overwrite
option. Plus, refactoring is much easier when you can just replace update()
with updateOne()
everywhere as opposed to not replacing it when using a doc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll make the changes now. Thanks guys 👍
Fixing variable not defined - out of scope
I screwed this up beyond the range of my git abilities. I will open a new pr with a new branch momentarily. |
per #6940 :
Make the API a bit more consistent with new method names. I also changed document.prototype.update to call updateOne to remove deprecation warning.
added 2 failing tests, made them pass, all existing tests pass.