Getting Started with MongoDB and PHP

Prem Tiwari - - 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.

Prem Tiwari

Prem Tiwari is the founder of and also a professional developer and a blogger by hobby.

Tags: , , , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.