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.
title: 'MongoDB with laravel',
description: 'Using MongoDB in Laravel application',
message: 'My first comment',
message: 'My second comments',
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:
- Big Data
- Content Management and Delivery
- E-commerce product catalog.
- Mobile and social networking sites.
- 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.