0

I want to increment all documents in a collection that contain a given nested array value. My objects each contain an "order" array with key:number values.

{
 _id: ...,
 order : array(
 foo: 34
 )
}

However, I can't figure out the correct MongoDB Query using the PHP MongoDB Native Driver.

 // Update all existing items with an order greater than this number
 $number = 2;
 $result = $collection->update(
 array("order" => array('foo' => array('$gt' => $number))),
 array('$inc' => array('order' => array('foo' => 1))),
 array("safe" => true)
 );
asked Oct 26, 2012 at 22:48

1 Answer 1

1

This is the PHP version of your MongoDB query and I add a multiple option additionally.

$collection->update(array('order.foo'=>array('$gt'=>2)), array('$inc' => array('order.foo'=>1)), array('multiple'=>true, 'safe'=>true));
answered Oct 28, 2012 at 7:58
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.