问题
$db->akis->update(
array("h" => (string) $_SESSION["_id"], "m" => array('$exists' => false)),
array('$set' => array("k" => $name)),
array("multiple" => true)
);
what i did in here is, if there is an m field, do not update k. What I want to add is, "if m field exists" update i instead of k field, how can I manage this ?
thank you
回答1:
I think you will need to do two separate queries here. That is just too conditional for MongoDB query parser to handle.
So you will need to put your logic into two separate queries with the second looking like:
$db->akis->update(
array("h" => (string) $_SESSION["_id"], "m" => array('$exists' => true)),
array('$set' => array("i" => $name)),
array("multiple" => true)
);
Running one after the other.
来源:https://stackoverflow.com/questions/12706530/mongodb-update-if-a-field-does-not-exist