eozzy
eozzy

Reputation: 68720

MongoDB: Updating the document while entirely replacing it

db.so.insert({"name":"Bob", "sex": "Male", "location": "France"})
db.so.update({"name":"Bob"}, // search
             {"name":"Bob", "occupation":"The Builder"}) // replace

I need to do a full update, ie. replace the entire document with the new object, but in this case the sex and location fields remain since I'm not providing those fields in the update query.

Upvotes: 1

Views: 108

Answers (1)

s7vr
s7vr

Reputation: 75964

May be you can try findAndReplace if your intention was to replace the document.

Upvotes: 2

Related Questions