MongoDB Essentials: Quick Project Practice Quiz Quiz

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.

  1. MongoDB Document Concept

    Which best describes a document in MongoDB?

    1. A JSON-like data structure storing key-value pairs
    2. A single string of text
    3. A fixed schema table row

    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.

  2. Database Selection

    What command is used to switch to the 'test' database in the MongoDB shell?

    1. switch test
    2. change test
    3. use test

    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.

  3. Primary Data Storage Unit

    In MongoDB, which component is responsible for storing collections of documents?

    1. Database
    2. Folder
    3. Index

    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.

  4. Adding Data

    Which method adds a single new document to a collection in MongoDB?

    1. insertOne()
    2. addDocument()
    3. putItem()

    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.

  5. Returning Query Results

    Which command retrieves all documents from a collection named 'users'?

    1. db.users.getAll()
    2. db.users.find()
    3. db.users.returnAll()

    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.

  6. Unique Document Identification

    What is the purpose of the '_id' field in each MongoDB document?

    1. It stores the user's name
    2. It defines the document's schema
    3. It uniquely identifies the document within a collection

    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.

  7. Collection Creation

    How are new collections usually created in MongoDB?

    1. With the makeCollection() command
    2. Automatically upon first document insertion
    3. Manually using file creation commands

    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.

  8. Deleting Documents

    Which method removes a single document from a MongoDB collection?

    1. deleteOne()
    2. eraseDoc()
    3. removeItem()

    Explanation: 'deleteOne()' deletes a single matching document. 'removeItem()' and 'eraseDoc()' are not standard MongoDB methods.

  9. Updating Documents

    Which method updates fields in an existing MongoDB document?

    1. updateOne()
    2. editRow()
    3. refresh()

    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.

  10. Document Query Syntax

    How would you query all documents where the field 'age' equals 25 in a collection named 'students'?

    1. db.students.search('age=25')
    2. db.students.retrieve({ age: 25 })
    3. db.students.find({ age: 25 })

    Explanation: The correct MongoDB syntax for this query is db.students.find({ age: 25 }). 'search' and 'retrieve' are not valid MongoDB query methods.