Tuesday, February 16, 2016

Introduction to MongoDB

MongoDB is an open-source document database, and leading NoSQL database. MongoDB is written in c++
This tutorial will give you great understanding on MongoDB concepts needed to create and deploy a highly scalable and performance oriented database.



Installing Mongo

http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
sudo apt-get update
sudo apt-get install -y mongodb-org

Remove the logs and the data if something got corrupted

sudo rm -rf /var/lib/mongodb/*
sudo rm -rf /var/log/mongodb/*

Start Mongo

sudo mongod --config /etc/mongod.conf --smallfiles
Verify that the mongod process has started successfully by checking the contents of the log file at /var/log/mongodb/mongod.log.

Some references to Mongo documentation

http://www.mongodb.com/architecture
http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/
http://docs.mongodb.org/manual/tutorial/getting-started/

Start the mongo shell

mongo

Different Mongo commands

show dbs
use mydb
j = { name : "mongo" }
k = { x : 3 }
db.testData2.insert( j )
db.testData2.insert( k )
show collections
db.testData2.find()
db.testData2.find( { x : 3 } )
db.testData.findOne()
db.testData.find().limit(3)
db.users.insert (

{
name: "praveen",
age: 30,
gender: "M",
groups: [ "news", "computer" ]
}
)

No comments:

Post a Comment

Xiaomi Launches 32-inch and 43-inch Mi TV 4A in India, Price Starting At ₹13,999

After launching the Mi TV 4 in India, Xiaomi has launched two new affordable smart TVs in India. The company has introduced a 43-inch ...