MongoDB is a free and open-source cross-platform document-oriented database program. It classified as a NoSQL database program, and using JSON-like documents with schemata.


Installation Steps:

1. Download and Install MongoDB server for Windows.

2. Download and extract MongoDB PHP driver

3. Rename any one file (Eg. php_mongo-1.6.8-5.6-vc11.dll) to php_mongo.dll and copy it to Extension directory known as ext directory.

4. Add the following line to your php.ini


5. Add Environment variable (Control Panel -> System and Security -> System -> Advanced system settings -> Environment variables) by editing PATH variable.

6. Create directory C:\data\db

7. Restart Apache server

8. Open CMD and start MongoDB server by  using command  Mongod

Basic queries:

  1. MongoDB Connection
$con = new MongoClient();
  1. Selection or Creation of Database (MySQL : Database)
$db = $con->database_name;
  1. Collection Creation (MySQL : Table)
$collection = $db->createCollection("collection_name");
  1. Document Insertion (MySQL : Insert – Row)
$document = array(
"key-1" => "value-1",
"key-n" => "value-n”
  1. View data (MySQL : Select)
$cursor = $collection->find(); 
foreach ($cursor as $document) {
    echo $document["key"];
  1. Updating data (MySQL : Update)
$collection->update(array("key"=>"old-value") , array('$set'=>array("key"=>"new-value")));
  1. Deletion of data (MySQL : Delete)

Leave a Reply