Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDb db.Collection.update() deleted my document

Tags:

mongodb

robo3t

I run an update statement on a mongodb database and it deleted my document! What did I do wrong?

This is the update statement:

db.Question.update( {Name: "IsSomeCompany"}, {ButtonValues: [0, 1, 2] } )

I am using Robomongo and the reply was Updated 1 record(s) in 22ms but when I checked the database the record was gone. What am I missing here?

like image 536
Eddy Avatar asked Dec 06 '22 17:12

Eddy


1 Answers

I use this syntax for updating multiple documents.

db.getCollection('YourDocument').update(
   { "matchingField" : "matchingValue"}, 
   { "$set": { "field": "value" } }, 
   { "multi": true } 
)

https://docs.mongodb.com/manual/tutorial/update-documents/

like image 106
Hamedz Avatar answered Jan 06 '23 10:01

Hamedz