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.
Which type of database does MongoDB belong to?
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.
How does MongoDB store its data by default?
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.
What is a 'collection' in MongoDB similar to in relational databases?
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.
Why does MongoDB use BSON instead of standard JSON to store its documents?
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.
Which field is commonly used as the unique identifier in a MongoDB document?
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.
In MongoDB, what happens when you insert a document into a collection in a new database?
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.
Which command is used in the MongoDB shell to display all 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.
What is the correct method to create a new collection named 'users' in MongoDB using the shell?
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.
Which feature allows MongoDB to handle increasing amounts of data by distributing it across multiple servers?
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.
What makes MongoDB schema-less compared to traditional databases?
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.
What is the primary purpose of creating indexes in a MongoDB collection?
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.
What does the MongoDB aggregation framework allow you to do?
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.
What is the size of an ObjectId in MongoDB?
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.
How do you switch to a different database in the MongoDB shell?
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.
Unlike relational databases that use tables, what does MongoDB use to organize and store records?
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.