Archive

Archive for April, 2016

MongoDb Introduction

April 7, 2016 Leave a comment

MongoDB Databse-
MongoDB is NoSql and document oriented database. MongoDB stores data using a flexible document data model that is similar to JSON.

Create Database-
>use yaju;

Show Database-
>show dbs

Drop Database-
To drop database, first use that database then use following command.
>db.dropDatabase();

Create Collection-
Collections are like table in MySql. We can create collection in two ways.

First, we can create empty collection
>db.createCollection(‘test’);

Second, we can create dynamic collection with insert command. Mongo check that collection if collection is exists then insert data in existing collection otherwise create new collection and insert data. That can be through followning command.
>db.testtable.insert({‘name’:’yajuvendra’},{‘name’:’yaj’});

Show collections-
Show all collection in a database use following command.
>show collections;

Insert document-
We can insert single document and multiple document as well.

Single document
>db.testtable.insert({‘name’:’yajuvendra’},{‘name’:’yaj’});
Multiple document
>db.testtable.insert([{‘name’:’yajuvendra’},{‘name’:’yaj’}, {‘name’:’yaju’},{‘name’:’yajkumar’}]);

Select document-
Select all document
>db.testtable.find();
Select particular document
> db.testtable.find({‘name’:’yaj’});

Remove document-
> db.testtable.remove({‘name’:’yaju’});

Update document-
> db.testtable.update({name:’yaj’},{$set:{name:’yaju_update’}})

%d bloggers like this: