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
- Documents and collections
- CRUD operations
- Indexes and queries
- Aggregation and NoSQL concepts
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?
- A Relational Database
- A NoSQL Database
- A Programming Language
- A CSS Framework
Answer: A NoSQL Database
MongoDB is a popular NoSQL document-oriented database.
2. Which company develops MongoDB?
- Oracle
- MongoDB Inc.
- Microsoft
Answer: MongoDB Inc.
MongoDB is developed and maintained by MongoDB Inc.
3. MongoDB stores data in the form of?
- Tables
- Documents
- Rows
- Arrays
Answer: Documents
MongoDB stores data as BSON documents.
4. Which format is used internally by MongoDB?
- XML
- JSON
- BSON
- CSV
Answer: BSON
MongoDB stores data internally in BSON (Binary JSON) format.
5. What is a collection in MongoDB?
- A group of databases
- A group of documents
- A group of tables
- 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?
- show dbs
- show databases
- list db
- display db
Answer: show dbs
The 'show dbs' command displays all available databases.
7. Which command is used to create or switch a database?
- use databaseName
- create databaseName
- switch databaseName
- new databaseName
Answer: use databaseName
The 'use' command creates or switches to a database.
8. Which method inserts one document into a collection?
- insertOne()
- addOne()
- insert()
- createOne()
Answer: insertOne()
insertOne() inserts a single document.
9. Which method inserts multiple documents?
- insertMany()
- addMany()
- createMany()
- multipleInsert()
Answer: insertMany()
insertMany() inserts multiple documents at once.
10. Which method retrieves documents from a collection?
- find()
- select()
- get()
- show()
Answer: find()
The find() method retrieves documents from a collection.
11. Which method returns only one matching document?
- findOne()
- find()
- getOne()
- selectOne()
Answer: findOne()
findOne() returns the first matching document from a collection.
12. Which method updates a single document?
- updateOne()
- update()
- modifyOne()
- replaceOne()
Answer: updateOne()
updateOne() updates the first document that matches the filter.
13. Which method updates multiple documents?
- updateMany()
- updateAll()
- modifyMany()
- replaceMany()
Answer: updateMany()
updateMany() updates all documents matching the filter.
14. Which method deletes one document?
- deleteOne()
- removeOne()
- delete()
- dropOne()
Answer: deleteOne()
deleteOne() removes a single matching document.
15. Which method deletes multiple documents?
- deleteMany()
- removeMany()
- dropMany()
- deleteAll()
Answer: deleteMany()
deleteMany() removes all matching documents.
16. Which command displays all collections in the current database?
- show collections
- show tables
- list collections
- 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?
- $and
- amp;&
- $all
- $match
Answer: $and
The $and operator joins multiple query conditions.
18. Which operator is used to match values greater than a specified value?
- $gt
- $greater
- $more
- $high
Answer: $gt
The $gt operator means 'greater than'.
19. Which operator is used to sort query results?
- sort()
- order()
- arrange()
- group()
Answer: sort()
The sort() method sorts the returned documents.
20. Which of the following is a major advantage of MongoDB?
- Flexible Schema
- High Scalability
- Fast Performance
- All of the above
Answer: All of the above
MongoDB offers a flexible schema, horizontal scalability, and excellent performance.