1

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

2 Answers 2

2

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));
Sign up to request clarification or add additional context in comments.

3 Comments

Should have added that, yes $ids is an array. I have tried with multiple and without. Pretty stumped here.
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.
I was able to the above to work in a controlled script file. Thanks so much.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.