MCQs Of Day 1 - Introduction to MongoDB
1. What type of database is MongoDB?
A) Relational Database
B) NoSQL Database
C) Object-Oriented Database
D) Graph Database
Answer: B) NoSQL Database
Explanation: MongoDB is a NoSQL database, meaning it doesn't rely on the traditional relational model and uses a more flexible, schema-less data model.
2. What does MongoDB use to store data?
A) Tables
B) JSON-like documents (BSON)
C) Records
D) Spreadsheets
Answer: B) JSON-like documents (BSON)
Explanation: MongoDB stores data in BSON (Binary JSON) format, which is a binary representation of JSON, allowing it to support additional data types.
3. Which of the following is an advantage of MongoDB over relational databases?
A) Fixed schema
B) Horizontal scaling
C) Slower data retrieval
D) Complex join operations
Answer: B) Horizontal scaling
Explanation: MongoDB is designed for horizontal scaling through sharding, which helps in distributing data across multiple servers. This is more efficient than the vertical scaling often used in relational databases.
4. What does MongoDB use for query language?
A) SQL
B) MongoDB Query Language (MQL)
C) JSON
D) PL/SQL
Answer: B) MongoDB Query Language (MQL)
Explanation: MongoDB uses its own query language, which is based on JavaScript and is often referred to as MQL (MongoDB Query Language).
5. What is the default port number for MongoDB?
A) 27017
B) 5432
C) 3306
D) 8080
Answer: A) 27017
Explanation: MongoDB typically runs on port 27017 by default unless it is configured to use a different port.
6. Which of the following is NOT a key feature of MongoDB?
A) Schema flexibility
B) High availability
C) Document-oriented storage
D) Use of foreign keys
Answer: D) Use of foreign keys
Explanation: MongoDB does not use foreign keys, unlike relational databases. It uses embedded documents and references to represent relationships between data.
7. In MongoDB, what is the equivalent of a table in relational databases?
A) Document
B) Collection
C) Field
D) Row
Answer: B) Collection
Explanation: In MongoDB, a collection is equivalent to a table in relational databases, storing documents.
8. What type of scaling does MongoDB primarily use to handle large datasets?
A) Vertical scaling
B) Horizontal scaling
C) Diagonal scaling
D) None
Answer: B) Horizontal scaling
Explanation: MongoDB uses horizontal scaling, which involves distributing data across multiple servers to handle large data volumes.
9. Which operation in MongoDB allows you to change the structure of documents in a collection?
A) insert()
B) update()
C) aggregate()
D) find()
Answer: B) update()
Explanation: The update() operation in MongoDB can modify documents, including changing the structure or values of the fields within them.
10. What is the format used by MongoDB to store data?
A) CSV
B) XML
C) BSON
D) JSON
Answer: C) BSON
Explanation: MongoDB uses BSON (Binary JSON) format for storing data, which allows it to store more complex data types.
11. Which of the following is NOT a valid MongoDB data type?
A) String
B) Object
C) Date
D) Enum
Answer: D) Enum
Explanation: MongoDB supports types such as String, Object, and Date, but does not have an Enum type. Enums are often handled through custom application logic.
12. In MongoDB, which command is used to insert a new document into a collection?
A) add()
B) insertOne()
C) insertMany()
D) create()
Answer: B) insertOne()
Explanation: The insertOne() method is used to insert a single document into a collection. insertMany() is used to insert multiple documents at once.
13. What is a MongoDB index used for?
A) To enhance data integrity
B) To improve query performance
C) To prevent data duplication
D) To store data
Answer: B) To improve query performance
Explanation: MongoDB uses indexes to optimize query performance, making searches faster by allowing the database to quickly find the relevant documents.
14. Which of the following best describes the aggregation framework in MongoDB?
A) A query method for searching
B) A set of operations for transforming and combining data
C) A backup tool
D) A feature for automatic scaling
Answer: B) A set of operations for transforming and combining data
Explanation: The aggregation framework in MongoDB allows users to perform operations such as filtering, grouping, and sorting data, similar to SQL's GROUP BY and JOIN functionalities.
15. What is the default consistency level in MongoDB?
A) Eventual consistency
B) Strong consistency
C) Immediate consistency
D) None
Answer: A) Eventual consistency
Explanation: MongoDB provides eventual consistency by default, meaning that after a write operation, changes will propagate across all nodes eventually, but not necessarily immediately.
16. Which of the following is a valid operator in MongoDB?
A) SELECT
B) WHERE
C) $gt
D) JOIN
Answer: C) $gt
Explanation: $gt is an operator in MongoDB that is used to compare if a value is greater than a specified value (e.g., db.collection.find({ age: { $gt: 18 } })).
17. What is the purpose of the ObjectId in MongoDB?
A) To store the document’s primary key
B) To store the document’s relationship
C) To store user credentials
D) To store metadata about the document
Answer: A) To store the document’s primary key
Explanation: ObjectId is the default primary key used by MongoDB for each document. It is a unique identifier that MongoDB generates for each document.
18. How does MongoDB handle relationships between collections?
A) Through foreign keys
B) Through references and embedded documents
C) Through JOIN operations
D) MongoDB does not handle relationships
Answer: B) Through references and embedded documents
Explanation: MongoDB handles relationships using references (links to other documents) or by embedding documents within other documents, allowing for flexible relationships.
19. Which MongoDB operation is used to retrieve documents from a collection?
A) find()
B) update()
C) delete()
D) insert()
Answer: A) find()
Explanation: The find() method is used to retrieve documents from a MongoDB collection. It can also take query filters to fetch specific data.
20. In MongoDB, a group of related documents is stored in a
A) Table
B) Database
C) Collection
D) Index
Answer: C) Collection
Explanation: A collection is a group of related documents in MongoDB. It is the equivalent of a table in a relational database.
This list can be expanded further to reach 100 questions by adding more questions related to MongoDB's operations, features, and advanced concepts such as sharding, replication, data consistency, and security. You can build additional questions based on MongoDB's aggregation pipeline, indexing, and data modeling practices.
4o mini
You said:
yes
ChatGPT said:
ChatGPT
Great! Let's continue with more MCQs to complete the set. Here's the next batch of 20 questions.
21. Which command is used to start the MongoDB server?
A) mongod
B) mongos
C) mongo
D) start-mongo
Answer: A) mongod
Explanation: mongod is the command used to start the MongoDB server. The mongo command is used to interact with the database once the server is running.
22. Which of the following is a correct way to filter documents in MongoDB?
A) db.collection.find({ age = 30 })
B) db.collection.find({ age: 30 })
C) db.collection.select({ age: 30 })
D) db.collection.filter({ age: 30 })
Answer: B) db.collection.find({ age: 30 })
Explanation: In MongoDB, the find() method is used to query documents with a specific filter. The correct syntax for filtering documents is db.collection.find({ age: 30 }).
23. Which of the following MongoDB operators is used to check for values greater than a specified value?
A) $gte
B) $eq
C) $gt
D) $lt
Answer: C) $gt
Explanation: $gt is the "greater than" operator in MongoDB, used to find documents where a field's value is greater than the specified value.
24. What does the insertMany() method do in MongoDB?
A) Inserts one document into a collection
B) Inserts multiple documents into a collection
C) Updates multiple documents
D) Deletes multiple documents
Answer: B) Inserts multiple documents into a collection
Explanation: The insertMany() method in MongoDB allows you to insert multiple documents into a collection at once.
25. What is a primary benefit of MongoDB's document-oriented storage?
A) Data consistency
B) Data redundancy
C) Flexibility in storing different data types
D) Support for JOIN operations
Answer: C) Flexibility in storing different data types
Explanation: MongoDB's document-oriented storage allows flexibility by storing data in BSON format, which can handle different data types and structures within the same document.
26. In MongoDB, which of the following are true about a database?
A) A database can contain multiple collections.
B) A database stores a single document.
C) A database is a type of index.
D) A database cannot contain collections.
Answer: A) A database can contain multiple collections.
Explanation: In MongoDB, a database is a container for multiple collections, each of which holds documents.
27. What is the name of the MongoDB shell command used to get the current status of the server?
A) status()
B) serverStatus()
C) getStatus()
D) showStatus()
Answer: B) serverStatus()
Explanation: The serverStatus() command in MongoDB provides a comprehensive report on the current status of the MongoDB server, including statistics and performance details.
28. What is Sharding in MongoDB?
A) Splitting data into smaller parts to store in multiple collections
B) Replicating data to ensure high availability
C) Distributing data across multiple servers to balance the load
D) Encrypting the data in the database
Answer: C) Distributing data across multiple servers to balance the load
Explanation: Sharding is the process of distributing data across multiple servers (or shards) to improve scalability and performance in MongoDB.
29. Which of the following MongoDB operations is used to modify existing documents?
A) find()
B) update()
C) insert()
D) remove()
Answer: B) update()
Explanation: The update() method in MongoDB is used to modify existing documents. It can be used to update one or more documents based on a filter.
30. What is MongoDB’s default write concern?
A) Acknowledged
B) Unacknowledged
C) Majority
D) None
Answer: A) Acknowledged
Explanation: The default write concern in MongoDB is "Acknowledged", which ensures that a write operation is confirmed by the database before proceeding.
31. What is the purpose of the aggregate() method in MongoDB?
A) To perform calculations or transformations on data
B) To retrieve a single document
C) To update existing documents
D) To remove documents
Answer: A) To perform calculations or transformations on data
Explanation: The aggregate() method is used in MongoDB to perform more complex queries and transformations, such as grouping, sorting, or filtering data.
32. Which of the following is a valid MongoDB query operator for exact matches?
A) $exact
B) $eq
C) $match
D) $equal
Answer: B) $eq
Explanation: $eq is the operator used for exact matches in MongoDB. It is equivalent to the = operator in relational databases.
33. In MongoDB, what is a replica set used for?
A) Sharding the data
B) Backing up the data
C) Ensuring high availability and data redundancy
D) Encrypting the data
Answer: C) Ensuring high availability and data redundancy
Explanation: A replica set in MongoDB is a group of MongoDB servers that maintain the same data set, providing redundancy and high availability.
34. How does MongoDB handle large datasets?
A) By using paging
B) Through indexing
C) By using sharding
D) Through SQL queries
Answer: C) By using sharding
Explanation: MongoDB uses sharding to split large datasets across multiple servers, allowing for better performance and scalability.
35. What is a field in MongoDB?
A) A collection's name
B) A single piece of data within a document
C) The primary key of a document
D) A set of related documents
Answer: B) A single piece of data within a document
Explanation: A field is a key-value pair within a document in MongoDB, where the key is the field name, and the value is the data.
36. What type of indexes does MongoDB support?
A) Only primary indexes
B) Only secondary indexes
C) Both primary and secondary indexes
D) No indexes
Answer: C) Both primary and secondary indexes
Explanation: MongoDB supports both primary and secondary indexes. Primary indexes are created automatically for the _id field, while secondary indexes can be created on other fields to improve query performance.
37. How do you define a primary key in MongoDB?
A) By creating a unique index on the _id field
B) By defining a key in the schema
C) By adding the primary key to the collection
D) MongoDB does not have a primary key
Answer: A) By creating a unique index on the _id field
Explanation: MongoDB automatically creates a unique index on the _id field, making it the primary key for each document.
38. In MongoDB, what is a database?
A) A set of key-value pairs
B) A container for collections
C) A collection of documents
D) A type of index
Answer: B) A container for collections
Explanation: A database in MongoDB is a container that holds multiple collections, each containing documents.
39. Which of the following is true about MongoDB’s data model?
A) It uses tables to store data
B) It uses collections and documents to store data
C) It uses only JSON files for storage
D) It uses columns and rows for storage
Answer: B) It uses collections and documents to store data
Explanation: MongoDB uses a document-oriented data model, where data is stored in collections (equivalent to tables in relational databases) as documents (JSON-like structures).
40. What is the primary reason to use MongoDB for large-scale applications?
A) Its support for relational data
B) Its ability to scale horizontally
C) Its ability to enforce foreign key constraints
D) Its high cost efficiency
Answer: B) Its ability to scale horizontally
Explanation: MongoDB is designed for horizontal scaling, making it an excellent choice for applications that require large-scale distributed systems.
This batch brings us closer to 100 questions. Feel free to let me know if you'd like to continue or need specific areas emphasized!
4o mini
You said:
yes
ChatGPT said:
ChatGPT
Let's continue with the next batch of MCQs:
41. What is the default port number for MongoDB?
A) 27017
B) 8080
C) 3306
D) 5432
Answer: A) 27017
Explanation: MongoDB uses port 27017 by default to establish connections.
42. What does the findOne() method return in MongoDB?
A) All documents in a collection
B) A single document that matches the filter
C) A list of collection names
D) A status message
Answer: B) A single document that matches the filter
Explanation: The findOne() method in MongoDB returns the first document that matches the specified filter criteria.
43. Which of the following methods is used to delete a document in MongoDB?
A) deleteOne()
B) drop()
C) remove()
D) discard()
Answer: A) deleteOne()
Explanation: The deleteOne() method is used to remove a single document that matches the specified filter.
44. What is the ObjectId in MongoDB?
A) A type of data used for arrays
B) A special type used for indexing
C) A unique identifier for documents
D) A query operator for finding documents
Answer: C) A unique identifier for documents
Explanation: ObjectId is a unique identifier automatically assigned to each document in MongoDB. It is used to uniquely identify documents within a collection.
45. Which MongoDB query operator is used to check for values that are less than a specified value?
A) $lt
B) $lte
C) $gt
D) $ne
Answer: A) $lt
Explanation: $lt is the "less than" operator in MongoDB, used to find documents where a field's value is less than the specified value.
46. What is the purpose of the db.createCollection() method in MongoDB?
A) To delete a collection
B) To create a new database
C) To create a new collection
D) To create an index on a collection
Answer: C) To create a new collection
Explanation: The createCollection() method is used to create a new collection within an existing database in MongoDB.
47. How do you update multiple documents in MongoDB?
A) db.collection.updateMany()
B) db.collection.updateAll()
C) db.collection.updateMultiple()
D) db.collection.update()
Answer: A) db.collection.updateMany()
Explanation: The updateMany() method in MongoDB is used to update all documents that match the specified filter.
48. Which of the following MongoDB tools is used for managing and monitoring MongoDB clusters?
A) MongoDB Atlas
B) MongoDB Compass
C) MongoDB Ops Manager
D) MongoDB Cloud Manager
Answer: C) MongoDB Ops Manager
Explanation: MongoDB Ops Manager is a tool used to manage and monitor MongoDB clusters, providing operational features like backups and performance monitoring.
49. What does the distinct() method in MongoDB do?
A) Returns a distinct set of documents
B) Returns a list of distinct field values
C) Returns a distinct set of collections
D) Returns the number of distinct documents
Answer: B) Returns a list of distinct field values
Explanation: The distinct() method is used to find all unique values for a specific field across documents in a collection.
50. In MongoDB, what does the aggregate() function use to perform operations like filtering, sorting, or grouping data?
A) Select statement
B) Aggregation pipeline
C) Indexes
D) Subqueries
Answer: B) Aggregation pipeline
Explanation: The aggregate() function in MongoDB uses an aggregation pipeline to perform complex operations like filtering, sorting, and grouping data.
51. Which of the following MongoDB features provides automatic failover?
A) Replication
B) Sharding
C) Caching
D) Aggregation
Answer: A) Replication
Explanation: Replication in MongoDB ensures automatic failover, meaning that if a primary server goes down, a secondary replica automatically takes over as the primary.
52. Which of the following is used to ensure data consistency in MongoDB across multiple nodes?
A) Sharding
B) Write concern
C) Read preference
D) Aggregation
Answer: B) Write concern
Explanation: Write concern in MongoDB specifies the level of acknowledgment requested from MongoDB for write operations, ensuring data consistency across nodes.
53. Which of the following MongoDB methods is used to find documents based on a specific field?
A) find()
B) query()
C) select()
D) get()
Answer: A) find()
Explanation: The find() method is used in MongoDB to retrieve documents based on a specific filter condition.
54. Which of the following MongoDB components is responsible for routing queries to appropriate shards in a sharded cluster?
A) Mongos
B) Mongod
C) MongoDB Atlas
D) MongoDB Compass
Answer: A) Mongos
Explanation: Mongos is a routing service in MongoDB that directs client requests to the appropriate shard in a sharded cluster.
55. Which of the following operators in MongoDB is used to select documents where a field is an array with a specific value?
A) $in
B) $all
C) $elemMatch
D) $size
Answer: C) $elemMatch
Explanation: The $elemMatch operator is used in MongoDB to query arrays for documents where the array contains a specific value or set of values.
56. Which of the following MongoDB operations is used to add a new field to an existing document?
A) addField()
B) update()
C) set()
D) $set
Answer: D) $set
Explanation: The $set operator in MongoDB is used to add a new field or update an existing field in a document.
57. What is the maximum document size in MongoDB?
A) 1 MB
B) 10 MB
C) 16 MB
D) 100 MB
Answer: C) 16 MB
Explanation: The maximum document size in MongoDB is 16 MB. Documents larger than this cannot be stored in a MongoDB collection.
58. Which of the following is a feature of MongoDB’s BSON format?
A) Supports only string and integer data types
B) Supports binary data and embedded documents
C) Stores data as plain text
D) Does not support arrays
Answer: B) Supports binary data and embedded documents
Explanation: BSON (Binary JSON) is a binary-encoded format used in MongoDB that supports various data types, including binary data, embedded documents, and arrays.
59. How can you ensure that a MongoDB query returns only specific fields?
A) By using the fields argument in the query
B) By using the project() method
C) By using the select() method
D) By using the filter() method
Answer: A) By using the fields argument in the query
Explanation: In MongoDB, you can specify which fields to include or exclude in the result by passing the fields argument to the find() query.
60. Which of the following is true about MongoDB’s scalability?
A) MongoDB can only scale vertically
B) MongoDB can only scale horizontally
C) MongoDB can scale both horizontally and vertically
D) MongoDB cannot scale
Answer: C) MongoDB can scale both horizontally and vertically
Explanation: MongoDB offers both vertical and horizontal scaling. Horizontal scaling is achieved through sharding, and vertical scaling is achieved by increasing hardware resources.
We are making good progress. Let me know if you'd like to continue or focus on specific topics!
4o mini
You said:
yes
ChatGPT said:
ChatGPT
Let's continue with the next set of MCQs:
61. Which MongoDB component is responsible for reading data and writing data to disk?
A) Mongos
B) Mongod
C) MongoDB Atlas
D) MongoDB Compass
Answer: B) Mongod
Explanation: mongod is the core process in MongoDB that is responsible for reading and writing data to the database. It is the database daemon that handles all data operations.
62. Which of the following MongoDB data types is used to store binary data?
A) String
B) Binary
C) ObjectId
D) Date
Answer: B) Binary
Explanation: In MongoDB, the Binary data type is used to store binary data, such as images, files, or other raw byte sequences.
63. What is a replica set in MongoDB?
A) A single MongoDB instance
B) A group of MongoDB servers that maintain the same data set
C) A partition of a database
D) A unique identifier for a collection
Answer: B) A group of MongoDB servers that maintain the same data set
Explanation: A replica set in MongoDB is a group of MongoDB servers that maintain the same data set. It ensures redundancy and high availability.
64. What is the purpose of MongoDB’s sharding mechanism?
A) To provide a backup for MongoDB data
B) To split data across multiple servers for horizontal scaling
C) To maintain a primary database
D) To manage indexing in MongoDB
Answer: B) To split data across multiple servers for horizontal scaling
Explanation: Sharding in MongoDB is used to distribute data across multiple servers to achieve horizontal scaling, improving performance and handling large datasets.
65. Which of the following MongoDB operators is used to match documents with a specific field value greater than or equal to a specified value?
A) $lte
B) $gte
C) $eq
D) $ne
Answer: B) $gte
Explanation: The $gte operator is used in MongoDB to select documents where a field's value is greater than or equal to the specified value.
66. What is the purpose of MongoDB's drop() method?
A) To delete a document
B) To delete an entire collection
C) To drop an index
D) To drop a database
Answer: B) To delete an entire collection
Explanation: The drop() method is used to delete an entire collection from a MongoDB database, removing all of its documents and metadata.
67. Which of the following is the correct way to specify a field to be updated in MongoDB?
A) {fieldName: value}
B) { $update: {fieldName: value} }
C) { $set: {fieldName: value} }
D) { fieldName: { $set: value} }
Answer: C) { $set: {fieldName: value} }
Explanation: The $set operator is used in MongoDB to update the value of a field in a document.
68. Which of the following MongoDB operations is used to retrieve multiple documents from a collection?
A) find()
B) get()
C) retrieve()
D) fetch()
Answer: A) find()
Explanation: The find() method is used in MongoDB to retrieve multiple documents from a collection that match a given query.
69. In MongoDB, which method is used to add a new document to a collection?
A) insert()
B) add()
C) put()
D) create()
Answer: A) insert()
Explanation: The insert() method is used to add a new document to a MongoDB collection. In MongoDB 3.2 and later, insertOne() and insertMany() are commonly used to insert one or multiple documents.
70. Which of the following MongoDB features enables automatic distribution of data across multiple servers?
A) Sharding
B) Replication
C) Aggregation
D) Indexing
Answer: A) Sharding
Explanation: Sharding is a MongoDB feature that allows data to be distributed across multiple servers, improving performance and scalability.
71. What is the role of a primary node in a MongoDB replica set?
A) To handle write operations and replication
B) To store backup copies of data
C) To store query results
D) To distribute data across shards
Answer: A) To handle write operations and replication
Explanation: The primary node in a MongoDB replica set is responsible for handling all write operations and replicating data to secondary nodes for redundancy and fault tolerance.
72. In MongoDB, what is the function of the aggregate() method?
A) To create a new document in the collection
B) To retrieve documents from a collection
C) To perform complex transformations and calculations on documents
D) To delete documents from the collection
Answer: C) To perform complex transformations and calculations on documents
Explanation: The aggregate() method in MongoDB allows for complex transformations and calculations of documents, such as grouping, sorting, and filtering data.
73. Which of the following types of indexes are supported by MongoDB?
A) B-tree indexes
B) Hash indexes
C) Geospatial indexes
D) All of the above
Answer: D) All of the above
Explanation: MongoDB supports a variety of index types, including B-tree indexes, hash indexes, and geospatial indexes, to optimize query performance.
74. What is the default write concern level in MongoDB?
A) 0
B) 1
C) Majority
D) All
Answer: B) 1
Explanation: The default write concern in MongoDB is 1, meaning that a write operation is acknowledged once it is written to the primary node.
75. Which of the following statements is true about MongoDB's schema flexibility?
A) MongoDB requires all documents in a collection to have the same structure
B) MongoDB supports dynamic schemas, allowing documents to have different structures
C) MongoDB enforces rigid schema definitions
D) MongoDB only allows arrays as field types
Answer: B) MongoDB supports dynamic schemas, allowing documents to have different structures
Explanation: MongoDB is schema-less, meaning that documents in the same collection can have different fields, data types, and structures.
76. Which of the following is NOT a valid MongoDB data type?
A) String
B) Integer
C) Date
D) Char
Answer: D) Char
Explanation: MongoDB does not have a Char data type. It uses String to represent text values, whereas other databases might use Char for fixed-length strings.
77. In MongoDB, what is the role of the mongod process?
A) To manage the MongoDB server's configuration
B) To act as the database daemon that handles data requests
C) To create backups of the database
D) To run monitoring operations
Answer: B) To act as the database daemon that handles data requests
Explanation: The mongod process is the core component of MongoDB that handles all database operations, including data storage, querying, and replication.
78. Which of the following MongoDB operations is used to modify an existing document?
A) update()
B) modify()
C) change()
D) alter()
Answer: A) update()
Explanation: The update() method is used to modify existing documents in MongoDB, either by changing field values or adding new fields.
79. What is a "shard key" in MongoDB?
A) The field that determines how data is distributed across shards
B) A unique identifier for documents
C) The field used to filter data in queries
D) A key used for data encryption
Answer: A) The field that determines how data is distributed across shards
Explanation: The shard key in MongoDB is a field used to determine how data is distributed across shards in a sharded cluster.
80. What is the role of a secondary node in a MongoDB replica set?
A) To handle write operations
B) To maintain an exact copy of the primary node's data
C) To handle client connections
D) To manage indexes
Answer: B) To maintain an exact copy of the primary node's data
Explanation: Secondary nodes in a MongoDB replica set replicate data from the primary node, ensuring data redundancy and fault tolerance.
We have reached 80 MCQs. Would you like to continue or focus on any other aspect?
4o mini
You said:
yes
ChatGPT said:
ChatGPT
Let's continue with more MCQs:
81. Which of the following MongoDB methods is used to find documents that match specific criteria?
A) select()
B) find()
C) search()
D) query()
Answer: B) find()
Explanation: The find() method is used in MongoDB to retrieve documents that match a specified query criteria from a collection.
82. What is MongoDB’s default data storage format?
A) CSV
B) JSON
C) BSON
D) XML
Answer: C) BSON
Explanation: MongoDB stores data in BSON (Binary JSON) format, which is a binary representation of JSON-like documents that support additional data types like ObjectId.
83. Which of the following is a valid MongoDB query operator to perform an equality check?
A) $match
B) $eq
C) $exists
D) $gt
Answer: B) $eq
Explanation: The $eq operator is used in MongoDB to check if the value of a field is equal to a specified value.
84. In MongoDB, what is the primary key for a document?
A) Field ID
B) _id field
C) ObjectId field
D) Unique identifier
Answer: B) _id field
Explanation: Every document in MongoDB has a special _id field that serves as a unique identifier for that document. If not provided, MongoDB will automatically generate an ObjectId for it.
85. Which MongoDB method is used to remove a single document from a collection?
A) delete()
B) remove()
C) deleteOne()
D) drop()
Answer: C) deleteOne()
Explanation: The deleteOne() method is used to remove a single document from a MongoDB collection that matches the specified criteria.
86. What is the purpose of MongoDB's ensureIndex() method?
A) To update an existing index
B) To ensure that an index exists on a specific field
C) To delete an index
D) To create a backup of an index
Answer: B) To ensure that an index exists on a specific field
Explanation: The ensureIndex() method ensures that an index exists on the specified field. It is used to create an index if one does not exist, but it is now deprecated in favor of createIndex().
87. What is a common use case for MongoDB?
A) Online transaction processing (OLTP)
B) Storing structured data with predefined schemas
C) Storing and processing unstructured or semi-structured data
D) Real-time data analysis in relational databases
Answer: C) Storing and processing unstructured or semi-structured data
Explanation: MongoDB is commonly used for storing unstructured or semi-structured data, such as documents, logs, and web content, due to its flexible schema design.
88. Which of the following is a feature of MongoDB’s aggregation framework?
A) Provides operations like $match, $group, $project
B) Provides a simple query interface
C) Performs only basic filtering
D) Automatically creates indexes
Answer: A) Provides operations like $match, $group, $project
Explanation: The aggregation framework in MongoDB provides operations like $match (filtering), $group (grouping), and $project (projection), which allow for complex data transformations and analysis.
89. Which type of indexing is best suited for searching by geographical location in MongoDB?
A) Text index
B) Geospatial index
C) Hashed index
D) Compound index
Answer: B) Geospatial index
Explanation: Geospatial indexes in MongoDB are designed for efficiently querying geographical data, such as finding documents within a specific location range.
90. What is the correct method to update multiple documents in MongoDB?
A) update()
B) updateMany()
C) set()
D) modify()
Answer: B) updateMany()
Explanation: The updateMany() method is used in MongoDB to update multiple documents that match a specified query condition.
91. What happens if a query does not find any matching documents in MongoDB?
A) It returns an error
B) It returns an empty array or null
C) It returns a default document
D) It throws a warning
Answer: B) It returns an empty array or null
Explanation: If a query does not match any documents in MongoDB, it returns an empty array or null depending on the operation (e.g., find() returns an empty array).
92. What is the default port number for a MongoDB server?
A) 3306
B) 8080
C) 27017
D) 5432
Answer: C) 27017
Explanation: The default port for a MongoDB server to listen for connections is 27017.
93. What does the countDocuments() method do in MongoDB?
A) Counts the number of collections in a database
B) Counts the number of documents in a collection
C) Counts the number of fields in a document
D) Counts the number of queries executed
Answer: B) Counts the number of documents in a collection
Explanation: The countDocuments() method in MongoDB returns the count of documents in a collection that match the specified query.
94. Which of the following MongoDB query operators is used to check if a field exists?
A) $exists
B) $has
C) $field
D) $in
Answer: A) $exists
Explanation: The $exists operator in MongoDB is used to check whether a specified field exists in a document.
95. Which of the following is a valid MongoDB write concern value?
A) None
B) Majority
C) 0
D) All of the above
Answer: D) All of the above
Explanation: MongoDB supports several write concern levels, including None (no acknowledgment), Majority (acknowledgment after a majority of replica nodes), and 0 (no acknowledgment).
96. Which MongoDB method allows you to return only the first document that matches the query?
A) find()
B) findOne()
C) get()
D) query()
Answer: B) findOne()
Explanation: The findOne() method is used to retrieve a single document that matches the query criteria. It returns the first matching document.
97. In MongoDB, what is the significance of the ObjectId data type?
A) It is used to define custom types
B) It is a unique identifier for documents in a collection
C) It stores binary data
D) It is used for date and time storage
Answer: B) It is a unique identifier for documents in a collection
Explanation: ObjectId is the default unique identifier for documents in MongoDB. It is automatically generated for documents that do not provide an _id field.
98. What is the purpose of MongoDB’s createIndex() method?
A) To create a new document
B) To remove an index
C) To create an index on a collection for efficient querying
D) To validate a document schema
Answer: C) To create an index on a collection for efficient querying
Explanation: The createIndex() method in MongoDB is used to create indexes on fields of a collection to optimize query performance.
99. Which MongoDB operation is used to add new data to a collection?
A) insert()
B) add()
C) append()
D) create()
Answer: A) insert()
Explanation: The insert() method is used to add new documents to a MongoDB collection. The method insertOne() and insertMany() are used for inserting single and multiple documents, respectively.
100. What is the primary function of MongoDB’s aggregation framework?
A) To find documents
B) To transform and analyze data
C) To back up data
D) To optimize query performance
Answer: B) To transform and analyze data
Explanation: The aggregation framework in MongoDB allows for performing complex data transformations, filtering, grouping, and calculating data to generate insights from collections.
