MongoCollection::insert
MongoCollection::save
MongoCollection
PHP Manual

# MongoCollection::remove

(PECL mongo >=0.9.0)

MongoCollection::remove — Remove records from this collection

### Description

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

### Parameters

`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.

### Return Values

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.

### Errors/Exceptions

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

### Changelog

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

### Examples

Example #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--;
}
?>`

### See Also

MongoDB core docs on » remove.

MongoCollection::insert
MongoCollection::save
MongoCollection
PHP Manual