Okay.. this is odd and annoying, so any help would be GREATLY appreciated. Here's my code:
Target.update {location_city: "New York"}, {location_country: "FUDGE!"}, {safe: true}, (err, res) ->
console.log "Updating with New York"
console.log res
console.log "Err #{err}"
No error, NADA. BUT only the FIRST document gets updated for some reason. When I run a find on the SAME query, I get multiple results.
Any help would be AWESOMELY appreciated.
findOneAndUpdate returns a document whereas updateOne does not (it just returns the _id if it has created a new document).
Mongoose save with an existing document will not override the same object reference. Bookmark this question. Show activity on this post.
In MongoDB, an upsert is an update query that inserts a new document if no document matches the given filter. Note that Mongoose will only inert at most one document even if you use updateMany() with upsert .
The $set operator replaces the value of a field with the specified value. The $set operator expression has the following form: { $set: { <field1>: <value1>, ... } } To specify a <field> in an embedded document or in an array, use dot notation.
multi
has to be true
.
So the correct query would be
Target.update {location_city: "New York"}, {location_country: "FUDGE!"}, {multi: true}, (err, res) ->
console.log "Updating with New York"
console.log res
console.log "Err #{err}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With