MongoDB MCQs – MongoDB Basics

MongoDB Basics is a foundational topic for understanding the NoSQL database. It introduces concepts such as databases, collections, and documents, and focuses on CRUD (Create, Read, Update, Delete) operations. These operations are vital for managing data efficiently. MongoDB supports flexible schema designs and various data types like String, Integer, Object, and Array, making it suitable for modern applications. For interview preparation, mastering these basics helps in explaining MongoDB’s advantages over traditional databases, practical query usage, and real-world data handling scenarios.

1.) What is the smallest unit of data in MongoDB?

A) Collection
B) Database
C) Field
D) Document

Answer: Option D

Explanation: In MongoDB, a document is the smallest unit of data, equivalent to a row in a relational database.

2.) What is a collection in MongoDB?

A) A group of tables
B) A group of fields
C) A group of documents
D) A group of databases

Answer: Option C

Explanation: A collection is a group of MongoDB documents, equivalent to a table in relational databases.

3.) Which of the following commands creates a new database in MongoDB?

A) createDatabase()
B) use database_name
C) db.create()
D) db.createDatabase()

Answer: Option B

Explanation: The use database_name command creates a new database if it does not already exist.

4.) Which of the following is not a valid MongoDB data type?

A) Array
B) Integer
C) Float
D) Boolean

Answer: Option C

Explanation: MongoDB does not explicitly have a “Float” type but uses Double to store decimal numbers.

5.) What is the default size limit for a single MongoDB document?

A) 8MB
B) 16MB
C) 32MB
D) Unlimited

Answer: Option B

Explanation: A single MongoDB document can be up to 16MB in size.

6.) Which command lists all collections in the current database?

A) show dbs
B) show collections
C) list collections
D) db.collections

Answer: Option B

Explanation: The show collections command lists all collections in the currently selected database.

7.) What is the command to insert a document into a collection?

A) db.collection.insert()
B) db.collection.add()
C) db.collection.create()
D) db.collection.update()

Answer: Option A

Explanation: The db.collection.insert() command is used to insert one or more documents into a MongoDB collection. While it’s more common now to use the more specific db.collection.insertOne() or db.collection.insertMany(), the insert() method remains valid for inserting documents.

8.) Which of the following is a valid BSON data type?

A) Date
B) XML
C) CSV
D) YAML

Answer: Option A

Explanation: BSON supports Date as a valid data type. XML, CSV, and YAML are formats for representing data, but they are not data types within BSON.

9.) How do you query all documents from a collection?

A) db.collection.findAll()
B) db.collection.find()
C) db.collection.query()
D) db.collection.getAll()

Answer: Option B

Explanation: The find() method retrieves all documents from a collection.

10.) Which operator is used to match documents where a field’s value is greater than a specified value?

A) $lt
B) $lte
C) $gt
D) $gte

Answer: Option C

Explanation: The $gt operator is used to find documents with a value greater than the specified one.

Leave a Reply

Your email address will not be published. Required fields are marked *