Recently work needs, to use MongoDB, this is the use of pecl installed, with the standard MONGO use or there is a difference, here does not tell the difference, only two more typical questions to how to deal with, specific documents you can directly refer to the official PHP document: http://php.net/ manual/zh/book.mongodb.php
Question 1:mongodb How to use _id to query records:
The ID here is the ID that MONGO automatically generates when we insert a record.
(1) from the record to get the ID
functionGet_oid ($query _result=Array()) {//The $query _result here is a record of the queryif(Empty($query _result)){ return false; }Else{ $id _obj=$query _result[' _id ']; $id _array=Get_object_vars($id _obj); return $id _array[' OID ']; }}
(2) query related records from _id
$id New Mongodb\bson\objectid ($origin _id); $origin _id $query array $id for the ID in the record); $query the query criteria for the normal query statement, using this condition, you can query the record of _ID as the specified ID.
Question 2: How to delete a collection
functionDrop_collection ($db,$collection){ $manager=NewMongodb\driver\manager (' mongodb://').$your _hosts.‘ /‘,$your _options); You need to change it to your host option.Try{ $server=$manager->selectserver (NewMongodb\driver\readpreference (mongodb\driver\readpreference::rp_primary)); $result=$server->executecommand ($db,NewMongodb\driver\command (["drop" + =$collection])); This sentence is the key to implementation, note the format }Catch(Exception $E){ return $E; } return $result;}
Pcel installation of two problems with MongoDB solution