MongoDB Interview Fundamentals Quiz Quiz

Explore key MongoDB concepts and essential NoSQL knowledge with this beginner-friendly quiz designed for interview preparation. Assess your understanding of documents, collections, BSON, scalability, and core MongoDB features.

  1. What is MongoDB primarily classified as?

    Which type of database does MongoDB belong to?

    1. NoSQL database
    2. Relational database
    3. Spreadsheet software
    4. Key-Value frontend

    Explanation: MongoDB is a NoSQL database, meaning it does not use fixed tables or schemas like relational databases. Relational databases are structured with tables, which is not how MongoDB stores data. Spreadsheet software and key-value frontend are not types of databases; they represent different tools and architectures not related to MongoDB's classification.

  2. Document Structure in MongoDB

    How does MongoDB store its data by default?

    1. In JSON-like documents
    2. As Excel sheets
    3. In CSV files
    4. As plain text

    Explanation: MongoDB stores data in JSON-like documents, providing a flexible, schema-less structure. Excel sheets and CSV files are formats for spreadsheets and tabular data storage, not native to MongoDB. Plain text storage lacks organization, whereas MongoDB uses BSON (a binary form of JSON) for structured storage.

  3. Definition of a Collection

    What is a 'collection' in MongoDB similar to in relational databases?

    1. A table
    2. A row
    3. A column
    4. An index

    Explanation: Collections in MongoDB are analogous to tables in relational databases—they group together documents of similar purpose. A row represents a single data entry, a column is a single attribute, and an index is used for speeding up queries, none of which capture the packet of records a collection or table provides.

  4. Purpose of BSON in MongoDB

    Why does MongoDB use BSON instead of standard JSON to store its documents?

    1. BSON supports extra data types and is optimized for performance
    2. BSON is easier to read by humans
    3. BSON and JSON are exactly the same
    4. BSON cannot store date values

    Explanation: BSON (Binary JSON) supports additional data types like ObjectId, dates, and binary data, and is faster for the database to process. While JSON is human-readable, BSON is meant for internal storage and efficiency. Saying BSON and JSON are the same is incorrect; BSON extends JSON. BSON actually adds the ability to store date values, so the last option is wrong.

  5. Primary Identifier for Documents

    Which field is commonly used as the unique identifier in a MongoDB document?

    1. _id
    2. primary
    3. docKey
    4. index_id

    Explanation: The '_id' field acts as the primary key for documents in MongoDB, ensuring uniqueness. 'primary' and 'docKey' are not default fields in MongoDB documents. 'index_id' is not a standard field name; indexes are separate entities. Only '_id' is created automatically for each document in every collection.

  6. Creating a New Database

    In MongoDB, what happens when you insert a document into a collection in a new database?

    1. The database and collection are created automatically
    2. An error is thrown
    3. Only the collection is created
    4. The operation is ignored

    Explanation: MongoDB creates databases and collections automatically when a new document is inserted into a non-existing collection of a non-existing database. It does not throw an error or ignore the command. Unlike some systems, you don’t need to manually create a collection before using it, and both database and collection are created together if needed.

  7. Listing Databases

    Which command is used in the MongoDB shell to display all databases?

    1. show dbs
    2. list databases
    3. find all dbs
    4. display databases

    Explanation: The 'show dbs' command lists all available databases in the MongoDB shell. The other options are not valid MongoDB shell commands—'list databases', 'find all dbs', and 'display databases' do not exist as MongoDB commands.

  8. Collection Creation Syntax

    What is the correct method to create a new collection named 'users' in MongoDB using the shell?

    1. db.createCollection('users')
    2. CREATE COLLECTION users
    3. make collection users
    4. add users

    Explanation: The standard MongoDB shell method is db.createCollection('users'). The other options resemble SQL or are not valid MongoDB commands. 'CREATE COLLECTION users' would be an SQL-like syntax, 'make collection users' and 'add users' are incorrect.

  9. Scalability in MongoDB

    Which feature allows MongoDB to handle increasing amounts of data by distributing it across multiple servers?

    1. Horizontal scaling
    2. Vertical stacking
    3. Serial processing
    4. Static partitioning

    Explanation: Horizontal scaling, or sharding, distributes data across multiple servers, allowing MongoDB to manage large datasets efficiently. Vertical stacking is not a common scaling method in databases. Serial processing describes processing one item at a time, and static partitioning lacks the flexibility of true horizontal scaling.

  10. Schema Flexibility

    What makes MongoDB schema-less compared to traditional databases?

    1. Documents in the same collection can have different structures
    2. All documents must have the same fields
    3. Schemas must be predefined before storage
    4. Data types are limited to numbers and text

    Explanation: A key aspect of MongoDB's schema-less design is that documents within a collection can have varying structures. Unlike traditional databases, MongoDB does not require predefined schemas. Strict uniformity and limited data types are features of older systems, not MongoDB.

  11. Role of Indexes

    What is the primary purpose of creating indexes in a MongoDB collection?

    1. To speed up search queries
    2. To back up data
    3. To encrypt the documents
    4. To restrict access to fields

    Explanation: Indexes are used to optimize search queries, making data retrieval much faster. Indexes do not provide backup or encryption functions, nor do they restrict field access. Their main purpose is to enhance query performance.

  12. Aggregation Framework

    What does the MongoDB aggregation framework allow you to do?

    1. Perform advanced data analysis and transformation operations
    2. Design user interfaces
    3. Encrypt connections
    4. Backup databases automatically

    Explanation: The aggregation framework lets you process and transform data, such as filtering, grouping, and summarizing documents. It does not aid in user interface design, connection encryption, or automating backups. Its primary focus is on data processing.

  13. ObjectId Format

    What is the size of an ObjectId in MongoDB?

    1. 12 bytes
    2. 8 bytes
    3. 16 bytes
    4. 32 bytes

    Explanation: ObjectId is a 12-byte unique identifier used as a primary key in MongoDB documents. The other options do not match the standard ObjectId size; 8, 16, and 32 bytes are incorrect for ObjectId in MongoDB.

  14. Switching Databases

    How do you switch to a different database in the MongoDB shell?

    1. use databaseName
    2. switch to databaseName
    3. database databaseName
    4. select databaseName

    Explanation: The 'use databaseName' command is standard in the MongoDB shell for switching databases or creating a new one. The other commands, such as 'switch to', 'database', and 'select', do not work in MongoDB's shell.

  15. Data Storage Comparison

    Unlike relational databases that use tables, what does MongoDB use to organize and store records?

    1. Collections of documents
    2. Grids of fields
    3. Stacks of schemas
    4. Structured matrices

    Explanation: MongoDB organizes records into collections, and these collections hold individual documents. Grids, stacks, and structured matrices are irrelevant to MongoDB's data organization. The core concept in MongoDB is the grouping of flexible documents in collections.