Hi Terry
Any ideas why my update was leaving original data?
Without the $set operator, the update() statement will replace the whole document. Your query should not result in a partial replacement of a document. Are you certain that the series of command you posted is correct?
Any ideas why my document disappeared?
The document didn’t disappear. It was replaced. This is because in the update() statement, you specified a replacement document, but you searched for the same document using a field that was overwritten by the update. If you search for the document using its _id field instead of restaurant_id, you would see the updated document. For example:
> db.test.find()
{
"_id": 0,
"a": 1
}
My test collection contains one document.
> db.test.update({a:1}, {b:1})
Updated 1 existing record(s) in 6ms
WriteResult({
"nMatched": 1,
"nUpserted": 0,
"nModified": 1
})
This will update a document containing the field a:1, and replace the whole document with b:1
> db.test.find()
{
"_id": 0,
"b": 1
}
Note that this is the same document that used to contain a:1. Now it contains b:1, but with the same _id:0 field (which shows that this is the one and the same document, since the _id field is immutable).
On another note, the command mongo --version will print the version of the mongo shell instead of the version of the server. To print the server’s version, you can use the command db.version() from inside the mongo shell.
Best regards
Kevin