How to use mongoDB in CodeIgniter

If you want to use mongoDB in your codeIgniter project as a database then this post may be helpful for you.

There are some simple steps to configure mongoDB in your project.

1.  Install PECL pakcage.

For this you can take help from official PHP site – http://php.net/manual/en/install.pecl.php

2. Download CodeIgniter library.

You have to download a library which helps to create connection with mongoDB https://github.com/bcit-ci/CodeIgniter

3. Install mongoDB.

You have to install mongoDB database in your system. According to your opearting system download installable file from https://docs.mongodb.com/manual/installation and install.

4. Set up library.

Extract library and you will get a config file which you need to place in application/config folder and a library file which shoulb be placed in application/libraries folder. In mongoDB config file enter your credentials like

 

5. Load library.

As a normal library whenever you want to use mongoDB in your project, you will need to load mongoDB library. For this you can use this code.

 

Here mongo_db_conn is a connection which can be used further for any CRUD purpose.

Mostly all methods are same as simple database connection.  For detailed documentation see https://github.com/bcit-ci/CodeIgniter/wiki

 

Here is my video for same purpose, may be it can help you to troubleshoot some problems.

1 Comment

  1. Nice post. thanks.

Leave a Reply