[SERVER-51208] New field `$setOnUpdate` will solve some problems Created: 29/Sep/20 Updated: 06/Oct/20 Resolved: 06/Oct/20 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | Vladimir Revenko | Assignee: | Eric Sedor |
| Resolution: | Duplicate | Votes: | 1 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||
| Participants: | |||||||||||||||||
| Description |
|
Hello! My name is Vladimir Revenko. I am NodeJS developer and active MongoDB user! ProblemTools such as Mongoose use the "timestamp" functionality. This makes it difficult in some cases. If we run without a `timestamps` parameter mongoose does this: {{db.cats.updateMany({}, { '$set': { name: 'Zildjian' }})}} MongoDB returns this: But, if we run with `timestamps` mongoose (with pre-hook) does this: db.cats.updateMany({}, { even if a `name` field is not modified, `updatedAt` field has been modified and MongoDB will update all matched docs and `modifiedCount` (`nModified` in Mongoose) will always be equal to `matchedCount` (`n` in Mongoose). I think there are other examples, but timestamps are the most obvious example. Suggestion for improvementMaybe you should separate the targeting update fields and the companion update fields at the mongodb level? Current usage works like this: db.cats.updateMany({}, { New usage could be like this: db.cats.updateMany({}, { Thе `$setOnUpdate` field means what data needs to be updated along with the data updated by the `$set` field.
I think this will add flexibility when working with the database and, at the same time, it will not break the existing code. Please see discussions with some examples:
With best regards, Email: vova@revenko.org |
| Comments |
| Comment by Vladimir Revenko [ 06/Oct/20 ] |
|
Thanks for the answer! I have read SERVER-42084, you can close this ticket |
| Comment by Eric Sedor [ 30/Sep/20 ] |
|
Hi vova@revenko.org, We're going to close this ticket as a duplicate of SERVER-42084, but appreciate your well-described request. Would you be willing to add your thoughts to that ticket and watch it for updates? Note that SERVER-42084 also offers a workaround that may be of benefit for Mongoose and MongoDB 4.2+. Sincerely, |
| Comment by Asya Kamsky [ 29/Sep/20 ] |
|
This appears to be similar if not identical to SERVER-42084
|