MongoCollection
PHP Manual

MongoCollection::remove

(PECL mongo >=0.9.0)

MongoCollection::removeRemove records from this collection

Beschreibung

public mixed MongoCollection::remove ( array $criteria [, array $options = array() ] )

Parameter-Liste

criteria

Description of records to remove.

options

Options for remove.

  • "justOne"

    Remove at most one record matching this criteria.

  • "safe"

    Check that the remove succeeded and how many items were removed.

Rückgabewerte

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.

Fehler/Exceptions

Throws MongoCursorException if the "safe" option is set and the remove fails.

Changelog

Version Beschreibung
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.

Beispiele

Beispiel #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--;
}

?>

Siehe auch

MongoDB core docs on » remove.


MongoCollection
PHP Manual