MongoDB Questions and Answers – Getting Started with MongoDB – 2

This set of MongoDB Questions and Answers for freshers focuses on “Getting Started with MongoDB – 2”.

1. When you query a collection, MongoDB returns a ________ object that contains the results of the query.
a) row
b) cursor
c) colums
d) none of the mentioned
View Answer

Answer: b
Explanation: The mongo shell then iterates over the cursor to display the results.

2. Point out the correct statement.
a) A database is a set of key-value pairs
b) A MongoDB deployment hosts a number of databases
c) A document holds a set of collections
d) All of the mentioned
View Answer

Answer: b
Explanation: A database holds a set of collections. A collection holds a set of documents.

3. Which of the following method returns true if the cursor has documents?
a) hasMethod()
b) hasNext()
c) hasDoc()
d) all of the mentioned
View Answer

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

4. ____________ method renders the document in a JSON-like format.
a) displayjson
b) print
c) printjson
d) printdoc
View Answer

Answer: c
Explanation: printjson() operation displays all documents.

advertisement
advertisement

5. Point out the wrong statement.
a) Documents have static schema in MongoDB
b) Eventually-consistent reads can be distributed over replicated servers
c) Indexes can include keys from embedded documents and arrays
d) None of the mentioned
View Answer

Answer: a
Explanation: Dynamic schema means that documents in the same collection do not need to have the same set of fields or structure, and common fields in a collection’s documents may hold different types of data.

6. Which of the following method is called while accessing documents using the array index notation?
a) cur.toArray()
b) cursor.toArray()
c) doc.toArray()
d) all of the mentioned
View Answer

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

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

7. The mongo shell and the drivers provide several cursor methods that call on the cursor returned by the _______ method to modify its behavior.
a) cursor()
b) find()
c) findc()
d) none of the mentioned
View Answer

Answer: b
Explanation: The method iterates completely the cursor, loading all the documents.

8. Which of the following method corresponds to Order by clause in SQL?
a) sort()
b) order()
c) orderby()
d) all of the mentioned
View Answer

Answer: a
Explanation: The sort() method orders the documents in the result set.

advertisement

9. The __________ method limits the number of documents in the result set.
a) limit()
b) limitOf()
c) limitBy()
d) none of the mentioned
View Answer

Answer: a
Explanation: limit() corresponds to the LIMIT statement in SQL.

10. Which of the following line skips the first 5 documents in the bios collection and returns all remaining documents?
a) db.bios.find().limit( 5 )
b) db.bios.find().skip( 1 )
c) db.bios.find().skip( 5 )
d) db.bios.find().sort( 5 )
View Answer

Answer: c
Explanation: The skip() method controls the starting point of the results set.

advertisement

Sanfoundry Global Education & Learning Series – MongoDB.

Here’s the list of Best Books in MongoDB.

To practice all areas of MongoDB for Freshers, Here is complete set of 1000+ Multiple Choice Questions and Answers.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.