Mongodb update: how to check if an update succeeds or fails?
Posted
by zmg
on Stack Overflow
See other posts from Stack Overflow
or by zmg
Published on 2010-06-02T23:42:08Z
Indexed on
2010/06/02
23:44 UTC
Read the original article
Hit count: 195
I think the title pretty much says it all.
I'm working with Mongodb in PHP using the pecl driver. My updates are working great, but I'd like to build some error checking into my funciton(s).
I've tried using lastError() in a pretty simple function:
function system_db_update_object($query, $values, $database, $collection) {
$connection = new Mongo();
$collection = $connection->$database->$collection;
$connection->$database->resetError(); //Added for debugging
$collection->update(
$query,
array('$set' => $values));
//$errorArray = $connection->$database->lastError();
var_dump($connection->$database->lastError());exit; // Var dump and /Exit/
}
But pretty much regardless of what I try to update (whether it exists or not) I get these same basic results:
array(4) {
["err"]=>
NULL
["updatedExisting"]=>
bool(true)
["n"]=>
float(1)
["ok"]=>
float(1)
}
Any help or direction would be greatly appreciated.
© Stack Overflow or respective owner