Labels

Monday, 18 January 2016

MongoDB CRUD Operations

MongoDB provides rich semantics for reading and manipulating data .CRUD stands for Create Read Update & Delete . CRUD terms are the foundation for all interactions with the database .

CREATE :

In MongoDB we can create the database , collection .

How to create the database in MongoDB ?

Syntax : Use < Database Name >

Ex: use MODEL

Test is the default database in MongoDB .

How to verify what is the current database ?

Just Type db in mongoshell

How to check the databases present in the server ?

Show dbs

Note: by default it will not show the database . In order to display the database we need to insert at least one document into it .
















Creating Collection :

Syntax :  db.createCollection(name,options)

Name : name of the collection to be created .

Options : It is an optional statement  used to specify memory size and indexing .

Ex: 
















READ:

You can find more about read from my blog post .

UPDATE:

MongoDB introduced update( ) and save( ) methods  to update the document into a collection .

The update( ) method update values in the existing document .

The save( ) method replaces the existing document with the document passed in the save ( ) method .

update( ) syntax :

db.collectionname.update (selection_criteria , updated_data)

Ex:







2 comments:

  1. Hi , I am your blog follower . I would like to learn MongoDB also. Please guide me what are pre required skills to learn MongoDB

    ReplyDelete
  2. Hi Amrita , Thanks for following my blog . Basic knowledge of database , text editor and execution of programs required.

    ReplyDelete