Take the 2-minute tour ×

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.

    array('$unset'=> array("f1"=>1)));
share|improve this question

2 Answers 2

up vote 2 down vote accepted

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:

   array('$unset'=> array("f1"=>true)), 
share|improve this answer
Should have added that, yes $ids is an array. I have tried with multiple and without. Pretty stumped here. –  Lloyd Jan 25 '12 at 22:03
Try doing a simple find with the $in to see if you can get it to work first. I updated my $unset array to use true instead of 1--not sure if that will help. –  Wes Freeman Jan 25 '12 at 22:19
I was able to the above to work in a controlled script file. Thanks so much. –  Lloyd Jan 26 '12 at 7:37

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).

share|improve this answer

Your Answer


