![download mongodb sample database download mongodb sample database](https://webimages.mongodb.com/_com_assets/cms/kkramzrpbqp49jl0e-sample-data-cluster-view-1.png)
In the above example, the second parameter is boolean type and used for justOne field of remove() method. $collection->remove(array("title"=>"MongoDB Tutorial"),false) Following is the code snippet to delete a document − In the following example, we will remove the documents that has the title MongoDB Tutorial. To delete a document, you need to use remove() method. $collection->update(array("title"=>"MongoDB"),Īrray('$set'=>array("title"=>"MongoDB Tutorial")))
Download mongodb sample database update#
Following is the code snippet to update a document − In the following example, we will update the title of inserted document to MongoDB Tutorial. To update a document, you need to use the update() method.
![download mongodb sample database download mongodb sample database](https://webassets.mongodb.com/_com_assets/cms/klbz3adgnrp935xmb-mongodb-atlas-load-sample-data-collections.png)
iterate cursor to display title of documents To select all documents from the collection, find() method is used.įollowing is the code snippet to select all documents − To insert a document into MongoDB, insert() method is used.įollowing is the code snippet to insert a document −Įcho "Collection selected succsessfully" $collection = $db->createCollection("mycol") When the program is executed, it will produce the following result −įollowing is the code snippet to create a collection − To make a connection, you need to specify the database name, if the database doesn't exist then MongoDB creates it automatically.įollowing is the code snippet to connect to the database − Now unzip the archive and put php_mongo.dll in your PHP extension directory ("ext" by default) and add the following line to your php.ini file − Make sure to download the latest release of it. Download the driver from the url Download PHP Driver. To use MongoDB with PHP, you need to use MongoDB PHP driver.