MongoDB Quiz

MongoDB is a document-oriented NoSQL database that stores data as JSON-like documents. This quiz tests collections, documents, CRUD operations, indexes, aggregation and how it differs from relational databases.

What this quiz covers

Study tip: Model the same data once in MongoDB and once in SQL tables to see where each approach is stronger.

Questions, answers and explanations

1. What is MongoDB?

  1. A Relational Database
  2. A NoSQL Database
  3. A Programming Language
  4. A CSS Framework

Answer: A NoSQL Database

MongoDB is a popular NoSQL document-oriented database.

2. Which company develops MongoDB?

  1. Oracle
  2. MongoDB Inc.
  3. Microsoft
  4. Google

Answer: MongoDB Inc.

MongoDB is developed and maintained by MongoDB Inc.

3. MongoDB stores data in the form of?

  1. Tables
  2. Documents
  3. Rows
  4. Arrays

Answer: Documents

MongoDB stores data as BSON documents.

4. Which format is used internally by MongoDB?

  1. XML
  2. JSON
  3. BSON
  4. CSV

Answer: BSON

MongoDB stores data internally in BSON (Binary JSON) format.

5. What is a collection in MongoDB?

  1. A group of databases
  2. A group of documents
  3. A group of tables
  4. A group of rows

Answer: A group of documents

A collection is similar to a table in relational databases.

6. Which command is used to show all databases?

  1. show dbs
  2. show databases
  3. list db
  4. display db

Answer: show dbs

The 'show dbs' command displays all available databases.

7. Which command is used to create or switch a database?

  1. use databaseName
  2. create databaseName
  3. switch databaseName
  4. new databaseName

Answer: use databaseName

The 'use' command creates or switches to a database.

8. Which method inserts one document into a collection?

  1. insertOne()
  2. addOne()
  3. insert()
  4. createOne()

Answer: insertOne()

insertOne() inserts a single document.

9. Which method inserts multiple documents?

  1. insertMany()
  2. addMany()
  3. createMany()
  4. multipleInsert()

Answer: insertMany()

insertMany() inserts multiple documents at once.

10. Which method retrieves documents from a collection?

  1. find()
  2. select()
  3. get()
  4. show()

Answer: find()

The find() method retrieves documents from a collection.

11. Which method returns only one matching document?

  1. findOne()
  2. find()
  3. getOne()
  4. selectOne()

Answer: findOne()

findOne() returns the first matching document from a collection.

12. Which method updates a single document?

  1. updateOne()
  2. update()
  3. modifyOne()
  4. replaceOne()

Answer: updateOne()

updateOne() updates the first document that matches the filter.

13. Which method updates multiple documents?

  1. updateMany()
  2. updateAll()
  3. modifyMany()
  4. replaceMany()

Answer: updateMany()

updateMany() updates all documents matching the filter.

14. Which method deletes one document?

  1. deleteOne()
  2. removeOne()
  3. delete()
  4. dropOne()

Answer: deleteOne()

deleteOne() removes a single matching document.

15. Which method deletes multiple documents?

  1. deleteMany()
  2. removeMany()
  3. dropMany()
  4. deleteAll()

Answer: deleteMany()

deleteMany() removes all matching documents.

16. Which command displays all collections in the current database?

  1. show collections
  2. show tables
  3. list collections
  4. display collections

Answer: show collections

The 'show collections' command lists all collections in the selected database.

17. Which operator is used for logical AND in MongoDB queries?

  1. $and
  2. amp;&
  3. $all
  4. $match

Answer: $and

The $and operator joins multiple query conditions.

18. Which operator is used to match values greater than a specified value?

  1. $gt
  2. $greater
  3. $more
  4. $high

Answer: $gt

The $gt operator means 'greater than'.

19. Which operator is used to sort query results?

  1. sort()
  2. order()
  3. arrange()
  4. group()

Answer: sort()

The sort() method sorts the returned documents.

20. Which of the following is a major advantage of MongoDB?

  1. Flexible Schema
  2. High Scalability
  3. Fast Performance
  4. All of the above

Answer: All of the above

MongoDB offers a flexible schema, horizontal scalability, and excellent performance.

Take the timed quiz