Open with fade-zoom animation

Stay ahead...
Receive latest updates directly in your Inbox!

MongoDB how to use it in Laravel Application.

MongoDB & How to use it in Laravel Application


MongoDB is a free and open-source cross-platform document-based NoSQL database program. Unlike RDBMS it doesn’t have a schema constraint. MongoDB uses JSON-like documents with schemas.

Terminologies for MongoDB


In MongoDB (or NoSQL) database is a container for collections. (unlike MySQL which contains tables).


Collections are equivalent to tables in RDBMS. But in NoSQL collections do not enforce a schema constraint (no fixed columns). A Collection contains Documents in JSON format and each document within a collection can have different fields. All similar type of documents is stored in a collection.


A document is a set of key-value pair present in JSON format. A document can have any number of field and any 2 documents in the same collection can have different fields.

Document Example:

Where to use MongoDB

MongoDB doesn’t have a schema constrain (Dynamic schema), it is fast, provided Rich queries, Highly scalable – Sharding and provides Geospatial indexing, which makes it a good choice for use in:

  1. Big Data
  2. Content Management and Delivery
  3. E-commerce product catalog.
  4. Mobile and social networking sites.
  5. Data hub

MongoDB with PHP & Laravel

For using MongoDB with PHP you will have to install MongoDB PHP driver – official installation guide

Laraval doesn’t have a out-of-box support for MongoDB. But thanks to the Laravel community, there is a
laravel-mongodb package which supports Eloquent model and Query builder. The best part about this package is – “It extends the original Laravel classes, so it uses exactly the same methods.

Most of the methods are same as Eloquent query builder methods and it supports many MongoDB specific operators.

For installation and complete documentation refer to the guide here.

No Comments

Leave a comment

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