Tuesday, August 30, 2011

Mongo: Invalid Modifier Specified{$var}

This is an exception thrown by MongoDB server when you mix the modifier "$set" with a normal variable during the update process. This is both observed in the shell and PHP Mongo. This is due probably to the difference in behavior of update that when you use "$set" would only partially update the object and the latter (using a common field/variable) would actually overwrite the entire document object which is a functionality conflict.

This is a hard to debug problem if your MongoDB driver/client wrappers are deep enough. I hope this helps you solve your problem.


PHP Mongo

$data =array('$set'=> array('value' => 1),
             'value2' => 2);
$condition = array("id"=>123);
$mongocollection->update($condition, $data);

Mongo Shell
  • Related Links Widget for Blogspot

No comments: