I'm trying to update a mongo document, using PHP and the update() function. However, when I do this, it replaces the WHOLE document with the value I wanted to update. How can I fix this?
The code I have written up to now: http://twaddlr.com/view/73 (Scroll down to the "update" function. It's a database wrapper I'm writting for my site)
The key is to use $set in the update, e.g. instead of this (sorry using JavaScript syntax here, not sure about the exact PHP driver syntax):
db.my_collection.update({hello: "world"}, {foo: "bar"})
you do
db.my_collection.update({hello: "world"}, {$set: {foo: "bar"}})
If you use $set, only the properties you specify will be updated, the whole document will not be replaced.
You can read more about this in the documentation, here: http://www.mongodb.org/display/DOCS/Updating#Updating-ModifierOperations
Edit: looking at your code, this is exactly what you do in the addRow method. Just do the same thing in update.
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