Introduction
MongoDB is a cross-platform, document oriented database that provides, high performance, high availability, and easy scalability. MongoDB works on concept of collection and document.
Comparison
Difference between MongoDB and RDMS.
Or Difference between MongoDB and MySQL.
*Concept
MongoDB |
RDMS |
Database |
Database |
Table |
Collection |
Document |
Row |
Field |
Column |
Embedded Document |
Table Join |
_id |
Primary Key |
*Database Operations
MongoDB |
RDMS |
create database test_database; |
use test_database |
show databases; |
show dbs |
drop database test_database; |
use test_database; db.dropDatabase() |
*Collection Operations
MongoDB |
RDMS |
create table products (…); |
db.createCollection(“products”) |
alter table testcoll add …; |
Automatically generated |
show tables; |
show collection |
drop table products; |
db.drop("products") |
*Document Operations
MongoDB |
RDMS |
insert into products values('a','b'); |
db.products.insert({ name : ‘a’ , type : “b” }) |
select * from products; |
db.products.find() |
select name from products where name = 'a' order by name; |
db.products.find({ name : 'a' }, { name : 1 }).sort({ name : 1 }) |
select count(*) from products; |
db.products.count() |
Installation
brew update
brew install mongodb
sudo mkdir /data/db
sudo mkdir /var/log/mongodb
sudo chmod go+w /data/db