Assess your foundational understanding of key MongoDB project concepts, from collections and documents to commands and primary data handling. Strengthen your core database skills with this practical, scenario-based quiz.
Which best describes a document in MongoDB?
Explanation: A MongoDB document stores data as key-value pairs in a flexible, JSON-like structure, supporting dynamic schemas. 'A fixed schema table row' is more typical of traditional relational databases, while 'A single string of text' does not represent structured data as used in MongoDB.
What command is used to switch to the 'test' database in the MongoDB shell?
Explanation: 'use test' is the correct command to switch to the test database in MongoDB. 'switch test' and 'change test' are not recognized commands in the MongoDB shell.
In MongoDB, which component is responsible for storing collections of documents?
Explanation: A MongoDB database contains collections, which in turn hold documents. 'Folder' is not a MongoDB data container, and 'Index' is used for search optimization, not for organizing documents directly.
Which method adds a single new document to a collection in MongoDB?
Explanation: The insertOne() method is used to add a single document to a MongoDB collection. 'addDocument()' and 'putItem()' are not part of the standard MongoDB API.
Which command retrieves all documents from a collection named 'users'?
Explanation: The db.users.find() command queries and returns all documents from the 'users' collection. 'db.users.getAll()' and 'db.users.returnAll()' are not valid MongoDB commands.
What is the purpose of the '_id' field in each MongoDB document?
Explanation: '_id' is automatically added by MongoDB to uniquely identify each document in a collection. It does not store user names or define schemas, which are managed differently.
How are new collections usually created in MongoDB?
Explanation: Collections in MongoDB are typically created automatically when the first document is inserted. There is no makeCollection() command, and file creation commands do not create MongoDB collections.
Which method removes a single document from a MongoDB collection?
Explanation: 'deleteOne()' deletes a single matching document. 'removeItem()' and 'eraseDoc()' are not standard MongoDB methods.
Which method updates fields in an existing MongoDB document?
Explanation: 'updateOne()' is used to update specific fields in a document. 'refresh()' is not a document modification command, and 'editRow()' does not exist in the MongoDB API.
How would you query all documents where the field 'age' equals 25 in a collection named 'students'?
Explanation: The correct MongoDB syntax for this query is db.students.find({ age: 25 }). 'search' and 'retrieve' are not valid MongoDB query methods.