Showing posts with label MongoDB. Show all posts
Showing posts with label MongoDB. Show all posts

Tuesday, 8 September 2015

MongoDB Installation + CRUD Guide

I am sharing the simplest method for MongoDB installation + db creation

Install mongodb from below link as per your OS


Go to your installed MongoDB directory/bin and create a folder with name "data"

Open cmd, go to your installed MongoDB directory/bin with the help of "cd"

execute following command:

> mongod.exe --dbpath "d:\mongo\data"  // as i have installed MongoDB in D:\mongo\ 


Wait for establishing connection

open another cmd, again go to your installed MongoDB directory/bin with the help of "cd" 

execute following command:

> mongo.exe 

Now you have access to CRUD your own db
Below is the sample code to create collection with document


> use test // it creates db with name "test"

> db.createCollection(collection_name) // it creates a Collection

> db.collection_name.insert({"name":"testing entry"})   // it creates document like "{"name":"testing entry"}"

> db.collection_name.find() // it will show all documents related to collection "collection_name"

> db.collection_name.drop() // it will delete the collection

> show dbs // it will show all databases

Note:
Mongo Db is based on no-sql. so it is bit faster 
May be there are some more professional/easy ways to do that.

Plz keep this information handy
and stay tuned, will keep sharing short articles about MeanSTACK!