MongoDB Basic interview Questions and Answers

1) What is MongoDB ? What are the features and advantages of MongoDB ?

   MongoDB is an free open-source cross-platform documnet-oriented database program.Classified as a NoSQL database program.MonogDB uses JSON-like documents with    schemas.

 Brilliant features and advantages of MongoDB are :

  1) Documnet-oriented

  2) Ad hoc queries

  3) Replication

  4) File storage

  5) Server-side JavaScript execution

  6) Capped collections

  7) Load balancing

2) What are the datatypes in MongoDB ?

   1) String  : String is used to store data.A string must be UTF 8 valid in MongoDB

   2) Integer : Integer is used to store the numeric can be 32 bit or 64 bit its depending up on the server your using

   3) Boolean : Boolean datatype is used to store boolean values.It just shows Yes/No values

   4) Double : Double datatype stores floating point values

   5) Min / Max : This datatype is used to compare a value against the lowest and highest bson values

   6) Arrays : This datatype is used to store a list or multiple values into a single key

   7) Object : Object datatype is used for embedded documents

   8) Symbol : It is generally used for languages that uses a specific type.

   9) Date: This datatype stores the current date or time in unix time format.

3) How to create a database in MongoDB ?

  Synatx: use Database-Name

 Example: >use sequelskillsDB

4) How to check the currently Selected database


5) How to check the existing database list in MongoDB ?

    >show dbs

6) You created database , if not listed in database list to display database


7)How to Drop a Database in MongoDB ?

 The dropDatabase command is used to drop a database. It also deletes the associated data files. It operates on the current database.



     Example : 1) >use sequelskillsDB

               2) >db.dropDatabase()

8) How to create a Collection in MongoDB ?

  db.createCollection(name, options) is used to create collection. But usually you don?t need to create collection. MongoDB creates collection automatically when you insert some documents


  db.createCollection(name, options)

 Example: 1) >use sequelskillsDB

          2) >db.createCollection("SEQUEL")

9) How to check the List of collections in MongoDB ?

    >show collections

10) How does MongoDB create collection automatically ?

    >db.SEQUEL.insert({"name" : "mydocument"})   

   >show collections 

11) How to see/check the inserted document, use the find() command?


12) How to Drop MongoDB collection ?

   db.collection.drop() method is used to drop a collection from a database. It completely removes a collection from the database and does not leave any indexes associated with the dropped collections.



  Example : 1) >use sequelskillsDB

            2) >db.SEQUEL.drop() 

13) How to create document in MongoDB ?

 db.collection.insert() method is used to add or insert new documents into a collection in your database.

 "db.collection.update()" method and "" method used for the same purpose



  Example:  >db.SEQUEL.insert({"name" : "mydocument"})

14) How to check the inserted documnet in MongoDB ?

 Synatx: db.collection_name.find()

 Example : db.SEQUEL.find()

15) How to insert the multiple documents in MongoDB ?

 If you want to insert multiple documents in a collection, you have to pass an array of documents to the db.collection.insert() method.

 var alldocuments = 
        Subject: "English", 
        details: { Duration: "6 months", Trainer: "Sonoo Jaiswal" }, 
        Batch: [ { size: "Medium", qty: 25 } ], 
        category: "Programming Language" 
        Subject: "Telugu", 
        details: { Duration: "6 months", Trainer: "Prashant Verma" }, 
        Batch: [ { size: "Small", qty: 5 }, { size: "Medium", qty: 10 }, ], 
        category: "Programming Language" 

     > db.SEQUEL.insert(alldocuments); 

16) How to Update inserted documnet in MongoDB ?

 update() method is used to update or modify the existing documents of a collection.



 Example : >db.SEQUEL.update({'course':'English'},{$set:{'course':'Hindi'}}) 

17) How to Delete a document in MongoDB ?

   the db.colloction.remove() method is used to delete documents from a collection. The remove() method works on two parameters.

  1. Deletion criteria: With the use of its syntax you can remove the documents from the collection.

  2. JustOne: It removes only one document when set to true or 1.


   db.collection_name.remove (DELETION_CRITERIA) 

 Example : >db.SEQUEL.remove( { type : "programming language" }, 1 )

18) How to Delete a all documnets in MonogDB ?


About Author: author 4 + years of Information Technology experience in understanding and analyzing the software and hardware engineering requirements, onsite and offshore management of product development. Expert work on design and development for windows,web,mobile Expert knowledge of C#,ADO.NET, ASP.Net MVC, ENTITY FRAMEWORK, LINQ,COLLECTIONS, JAVASCRIPT,AngularJs 1.0,Angular2, Jquery,Jquery-Ajax, SQL SERVER, XAML,Windows phone 8.1 Good knowledge of WCF-Restful services,WCF, WEB API-Services ,Web- Services,MIcrosoft-Azure,JUICE UI,HTML,CSS,AJAX Read More...

Join him on Google+ | Facebook | Linkedin

No comments