update with upsert: true doesn't work sometimes
See original GitHub issueI need to keep only one document in my nedb.
So I make db.update({ active: true }, data, { upsert: true }, function (err, savedNum) { ... })
where data is { active: true, name: 'name', token: '1234567890' }
It saves doc and keep it only one yet on a first time. But second time while updating (data is almost the same, only token is different), it doesn’t replace existing document - it adds another one…
On the third time it stops to add new ones, but replace one of existing ones…
Issue Analytics
- State:
- Created 10 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
mongodb update with upsert:true does not act as in insert
As it turns out, it works only when I use insert , if upsert:true is provided with the update, the new inserted doc...
Read more >UpdateMany, Upsert does not perform insert - MongoDB
If an upsert operation results in an insert, the query must include an exact equality match on the array field in order to...
Read more >Problem Solving: Mongoose Validators Don't Run on Update ...
If the upsert flag is true, we update the existing documents and create the ones that don't. If the document doesn't exist, we...
Read more >Upsert in SQL: What is an upsert, and when should you use ...
If the employee ID exists in the table, update that row with the new information. · If the employee ID doesn't exist in...
Read more >Collections | Meteor API Docs
When you write to the database on the client ( insert , update , remove ) ... It works just like any other...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@voronianski this is not a bug. The datafile is append only but gets autocompacted upon every reload. If you look closely, you’ll see that the documents in your file habe the same _id, meaning they re in fact the different states of the same doc, the last one being the latest one
When checking the contents of a db, never look at the file, always do a db.find()
@louischatriot thanks, didn’t notice it 😃 panic without reason 😃