Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

problems with deleting document in mongodb using php

Tags:

php

mongodb

I try to delete document in mongodb using php, I it fails and I get a waring:

Warning: MongoCollection::remove() expects parameter 2 to be boolean, array given

$mongo = new Mongo();
$db = $mongo->test; 
$collection = $db->subscribers;
$collection->remove(array( 'LISTID' => 49));

Could you please tell me what causes an error? I phpinfo() shows:

mongo
MongoDB Support enabled
Version     1.0.4+

Directive   Local Value Master Value
mongo.allow_persistent  On  On
mongo.auto_reconnect    On  On
mongo.chunk_size    262144  262144
mongo.cmd   $   $
mongo.default_host  localhost   localhost
mongo.default_port  27017   27017
mongo.utf8  1   1

It's strange, the documentation say the function looks like:

public mixed MongoCollection::remove ( array $criteria [, array $options = array() ] )
like image 396
Oleg Avatar asked Sep 19 '26 16:09

Oleg


1 Answers

You need to specify the remove options:

$collection->remove(array('type' => 94), array("justOne" => true));

for more info, see the online manual

like image 93
Nicolas Modrzyk Avatar answered Sep 21 '26 11:09

Nicolas Modrzyk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!