I am trying to update and insert a record called ‘enabled’ in all entries that have a ‘title’
{
"_id": ObjectId("50310c48ba76882419000001"),
"title": "XKCD",
"online": true
}
{
"_id": ObjectId("50310c48ba76882419000000"),
"title": "Calvin and Hobbes",
"author": "Bill Watterson"
}
Here is my attempt but i seem to be having some problems.
When i run this, nothing happens.
Any help would be appreciated
$mongo = new Mongo();
$db = $mongo->mydb;
$col = $db->members;
$query = array('title'=>array('$exist' => true));
$col->update($query, array('enabled' => '0' ));
I think your problem exists here:
This will actually replace all but the unmutable
_idfield withenabled: 0. Try the$setopreator:http://www.mongodb.org/display/DOCS/Updating#Updating-%24set