downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

MongoCollection::save> <MongoCollection::insert
[edit] Last updated: Fri, 18 Sep 2009

view this page in

MongoCollection::remove

(PECL mongo >=0.9.0)

MongoCollection::removeRemove records from this collection

Описание

public boolean MongoCollection::remove ( array $criteria [, boolean $justOne = FALSE ] )

Параметри

criteria

Description of records to remove.

justOne

Remove at most one record matching this criteria.

Връщани стойности

Returns if the command was executed successfully.

Примери

Example #1 MongoCollection::remove() with justOne example

<?php

$radioactive 
$db->selectCollection('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), true);
    
$halflife--;
}

?>


add a note add a note User Contributed Notes MongoCollection::remove
David Winter 02-Jan-2010 05:55
To remove a document based on its ID, you need to ensure that you pass the ID as a MongoID object rather than just a string:

<?php
$id
= '4b3f272c8ead0eb19d000000';

// will not work:
$collection->remove(array('_id' => $id), true);

// will work:
$collection->remove(array('_id' => new MongoId($id)), true);
?>

 
show source | credits | stats | sitemap | contact | advertising | mirror sites