Reputation: 1403
From the MongoDB command line I can do
db.user.update({userid: {$in: [435707147,88513850,466518582]}},{$unset: {f1 : 1}})
Which will remove the variable f1 from all user objects in the DB. How would you translate that to PHP syntax?
I the following runs with no error, but no changes are made to the DB.
$db->user->update(array("userid"=>array('$in'=>$ids)),
array('$unset'=> array("f1"=>1)));
Upvotes: 1
Views: 881
Reputation: 2646
Wes is correct, you will likely want to use 'multiple'=>true
. If the the $in query alone still doesn't return any results, make sure the elements in $ids
are integers and not strings (try calling gettype()
on each element).
Upvotes: 0
Reputation: 33175
Do you set $ids = array(435707147, 88513850, 466518582);
?
You probably also need to say it with 'multiple'=>true
to update all of them at once:
$db->user->update(array("userid"=>array('$in'=>$ids)),
array('$unset'=> array("f1"=>true)),
array('multiple'=>true));
Upvotes: 2