0

Following this question I gather that upsert: false and multi: true fields need to be set for this to work.

However, when I try to code this in PHP, I have a problem:

$conn = new Mongo("mongodb://foo:bar@localhost:27017");
$db = $conn->selectDB("someDB");

$data = array('$rename' => array(
  'nmae' => 'name'
));
$db->command(array(
  'findAndModify' => 'foo',
  'update' => $data,
  'upsert' => 'false',
  'multi' => 'true'
));

After running this script, only the first document with the nmae typo is changed to name; the rest still say nmae. The same as if I had run it without the upsert and multi options.

I also tried this:

$data = array('$rename' => array(
  'nmae' => 'name'
),
'upsert' => 'false',
'multi' => 'true'
);
$db->command(array(
  'findAndModify' => 'foo',
  'update' => $data
));

But that does the same thing.

Any way to get this working?

Community
  • 1
  • 1
A. Duff
  • 4,097
  • 7
  • 38
  • 69

1 Answers1

2

The findAndModify query doesn't have a "multi" option: http://www.php.net/manual/en/mongocollection.findandmodify.php

What you probably want to use is update instead: http://www.php.net/manual/en/mongocollection.update.php

unkhan
  • 280
  • 1
  • 6
  • Thanks, but that still doesn't seem to work on every document the way the corresponding command does when run in MongoDB. What I have is `$db->someDB->update(array(), $data, array('$multi' => true, '$upsert' => false));` Maybe the `multi` option was never implemented in the PHP-Mongo Driver. – A. Duff Dec 17 '13 at 21:30
  • 1
    nvm. Didn't read the documentation closely enough. It should be `array('multiple' => true)` – A. Duff Dec 17 '13 at 21:35