MongoCollection
PHP Manual

MongoCollection::remove

(PECL mongo >=0.9.0)

MongoCollection::removeRemove records from this collection

Descrição

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

Parâmetros

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.

Valor Retornado

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.

Erros

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

Histórico

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.

Exemplos

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

?>

Veja Também

MongoDB core docs on » remove.


MongoCollection
PHP Manual