Copy CodeThe code is as follows:
This is the default connection to the local 27017 port, of course you can also connect the remote host such as 192.168.0.4:27017, if the port is 27017, the port can be omitted
$m = new Mongo ();
Select the comedy database, if not previously the database will be automatically created, you can also use $m->selectdb ("comedy");
$db = $m->comedy;
Select the collection collection inside the comedy, which is equivalent to the table inside the RDBMS, and also-can be used
$collection = $db->collection;
$db->selectcollection ("collection");
Add an Element
$obj = Array ("title" = "Calvin and hobbes-". Date (' i:s '), "author" = "Bill Watterson");
Adding $obj to the $collection collection
$collection->insert ($obj);
Add another element
$obj = Array ("title" = "xkcd-". Date (' i:s '), "online" = true);
$collection->insert ($obj);
Querying all the records
$cursor = $collection->find ();
Traverse a document in all collections
foreach ($cursor as $obj)
{
echo $obj ["title"]. "
\ n ";
}
Delete all data
$collection->remove ();
Remove name as HM
$collection->remove (Array (' name ' = ' HM '));
Disconnecting MongoDB connections
$m->close ();
?>
http://www.bkjia.com/PHPjc/325839.html www.bkjia.com true http://www.bkjia.com/PHPjc/325839.html techarticle Copy the code as follows: PHP//Here is the default connection to the local 27017 port, of course you can also connect remote host such as 192.168.0.4:27017, if the port is 27017, the port can be omitted ...