(PECL mongo >=0.9.0)
MongoCollection::remove — Remove records from this collection
Description of records to remove.
Options for remove.
"justOne"
Remove at most one record matching this criteria.
"safe"
Check that the remove succeeded and how many items were removed.
If "safe" is set, returns an associative array with the status of the remove ("ok"), the number of items removed ("n"), and any error that may have occured ("err"). Otherwise, returns TRUE if the remove was successfully sent, FALSE otherwise.
Throws MongoCursorException if the "safe" option is set and the remove fails.
Versão | Descrição |
---|---|
1.0.5 | Changed second parameter to an array of options. Pre-1.0.5, the second parameter was a boolean indicating the "justOne" option and there was no safe option. |
Exemplo #1 MongoCollection::remove() with justOne example
<?php
$radioactive = $db->radioactive;
// count how much more plutonium there is
$remaining = $radioactive->count(array('type' => 94));
$halflife = $remaining/2;
// remove half of it
while ($halflife > 0) {
$uranium->remove(array('type' => 94), array("justOne" => true));
$halflife--;
}
?>
MongoDB core docs on » remove.