Crud Concepts And Operation(Engineering > Computer Science And Engineering > Mongodb ) Questions and Answers

Question 1. MongoDB stores all documents in :
  1.    tables
  2.    collections
  3.    rows
  4.    All of the mentioned
Explanation:-
Answer: Option B. -> collections


Collections are analogous to a table in relational databases.



Question 2. Which of the following method returns true if the cursor has documents ?
  1.    hasMethod()
  2.    hasNext()
  3.    hasDoc()
  4.    All of the mentioned
Explanation:-
Answer: Option B. -> hasNext()


hasNext() returns true if the cursor returned by the db.collection.find() query can iterate further to return more documents.



Question 3. In MongoDB, _________ operations modify the data of a single collection.
  1.    CRUD
  2.    GRID
  3.    READ
  4.    All of the mentioned
Explanation:-
Answer: Option A. -> CRUD


Data modification refers to operations that create, update, or delete data.



Question 4. After starting the mongo shell, your session will use the ________ database by default.
  1.    mongo
  2.    master
  3.    test
  4.    primary
Explanation:-
Answer: Option C. -> test


At any time,db operation at the mongo shell is used to report the name of the current database.



Question 5. Which of the following method is called while accessing documents using the array index notation ?
  1.    cur.toArray()
  2.    cursor.toArray()
  3.    doc.toArray()
  4.    All of the mentioned
Explanation:-
Answer: Option B. -> cursor.toArray()


The toArray() method returns an array that contains all the documents from a cursor.



Question 6. Which of the following method returns one document ?
  1.    findOne()
  2.    findOne1()
  3.    selectOne()
  4.    All of the mentioned
Explanation:-
Answer: Option A. -> findOne()


MongoDB provides a db.collection.findOne() method as a special case of find() that returns a single document.



Question 7. Which of the following is second argument to projection ?
  1.    findOne()
  2.    findOne1()
  3.    selectOne()
  4.    find()
Explanation:-
Answer: Option D. -> find()


Projections are the second argument to the find() method,which specify a list of fields to return or list fields to exclude in the result documents.



Question 8. Which of the following will display complete list of available cursor flags ?
  1.    cursor.Option()
  2.    cursor.addOption()
  3.    cursor.addOptions()
  4.    All of the mentioned
Explanation:-
Answer: Option B. -> cursor.addOption()


You should either close the cursor manually or exhaust the cursor.



Question 9. The ________ message is used to update a document in a collection.
  1.    UPDATE
  2.    OP_UPDATE
  3.    OP_UPDATES
  4.    All of the mentioned
Explanation:-
Answer: Option B. -> OP_UPDATE


Only the OP_QUERY and OP_GET_MORE messages result in a response from the database.



Question 10. The mongo shell and the MongoDB drivers use __________ as the default write concern.
  1.    Nacknowledged
  2.    Acknowledgement
  3.    Acknowledged
  4.    All of the mentioned
Explanation:-
Answer: Option C. -> Acknowledged


MongoDB allows clients to read documents inserted or modified before it commits these modifications to disk, regardless of write concern level or journaling configuration.