Getting Started with MongoDB and PHP

| Last Updated: | In: Mysql, PHP Tutorial


This tutorial provides an introduction to basic database operations using the mongo shell. MongoDB is a document database that provides high performance, high availability, and easy scalability.

MongoDB is a free and open-source cross-platform document-oriented database program with NoSQL database. It stores data in json format. MongoDb is developed by MongoDB Inc in 2007.

How Access MongoDB from PHP

To access MongoDB from PHP you need:

1) The MongoDB server running. The server is the “mongod” file,
not the “mongo” client (note the “d” at the end).
2) The MongoDB PHP driver installed.

Make a connection string & Select a database

To make connection string & select the database in php simply used the below snippets.
Create a config.php file.

Select all Data

Delete Data

In the part of useful CRUD there is ability to delete the data records. MonogoDB provides a method remove() for this which only takes an array of data attributes as the criteria to removing the data records.

Update the data

In the CRUD operations there is also ability to update the records. In MongoDB have a simple method save() for this which require an array of criteria to know which records would be updated. Bellow is the example fo updating the data records.


About: Prem Tiwari

Prem Tiwari is the founder of freewebmentor.com and is a professional developer who has vast experience in PHP and open source technologies. Apart from this, he is a blogger by hobby and also he has been a regular speaker of WordPress sessions in various IT Companies.


You may also like:


, , , , , , , ,