Question 1 of 50
What type of database is MongoDB classified as?
A
Graph Database
B
NoSQL Document Database
C
Relational Database Management System (RDBMS)
D
Key-Value Store
Not quite. Try another option.
Answer: NoSQL Document Database
MongoDB is a NoSQL database that stores data in flexible, JSON-like documents.
Question 2 of 50
In MongoDB, what is the equivalent of a 'Table' in an RDBMS?
A
Field
B
Collection
C
Cluster
D
Document
Not quite. Try another option.
Answer: Collection
A collection in MongoDB is a group of documents, functioning similarly to a table in relational databases.
Question 3 of 50
Which format does MongoDB use to store data internally?
A
JSON
B
YAML
C
BSON
D
XML
Not quite. Try another option.
Answer: BSON
MongoDB uses BSON (Binary JSON), which allows for faster traversal and support for more data types than standard JSON.
Question 4 of 50
What is the default field added to every MongoDB document to act as a primary key?
A
id
B
key
C
_id
D
primary_id
Not quite. Try another option.
Answer: _id
MongoDB automatically assigns a unique _id field (ObjectId) to every document if one is not provided.
Question 5 of 50
Which command is used in the MongoDB shell to switch to a specific database?
A
switch database_name
B
db database_name
C
use database_name
D
connect database_name
Not quite. Try another option.
Answer: use database_name
The use command allows you to switch context to a specific database or create it if it doesn't exist.
Question 6 of 50
What happens if you switch to a database that does not exist and insert data?
A
It asks for confirmation to create it.
B
MongoDB creates the database automatically.
C
The data is discarded.
D
It throws an error.
Not quite. Try another option.
Answer: MongoDB creates the database automatically.
MongoDB creates databases lazily; the database is created only when the first collection or document is inserted.
Question 7 of 50
Which command displays the list of existing databases in the shell?
A
display dbs
B
show dbs
C
list databases
D
show databases all
Not quite. Try another option.
Answer: show dbs
show dbs (or show databases) lists all databases on the server that contain data.
Question 8 of 50
In MongoDB, a 'Row' in an RDBMS is equivalent to a:
A
Field
B
Table
C
Collection
D
Document
Not quite. Try another option.
Answer: Document
A document is a single record in a collection, analogous to a row in a relational table.
Question 9 of 50
Which command is used to explicitly create a collection with specific options?
A
db.newCollection('name')
B
db.insertCollection('name')
C
db.collection.create('name')
D
db.createCollection('name')
Not quite. Try another option.
Answer: db.createCollection('name')
db.createCollection() is used to explicitly create a collection, often to set validation rules or capped collection settings.
Question 10 of 50
How do you delete a collection named 'users' in the MongoDB shell?
A
db.users.remove()
B
db.users.delete()
C
db.users.drop()
D
db.dropCollection('users')
Not quite. Try another option.
Answer: db.users.drop()
The drop() method is called on a collection object to remove it entirely from the database.
Question 11 of 50
Which command deletes the currently selected database?
A
db.dropDatabase()
B
db.deleteDatabase()
C
db.removeDatabase()
D
delete db
Not quite. Try another option.
Answer: db.dropDatabase()
db.dropDatabase() removes the current database and its associated files.
Question 12 of 50
Which method is used to insert a single document into a collection?
A
db.collection.push()
B
db.collection.addOne()
C
db.collection.put()
D
db.collection.insertOne()
Not quite. Try another option.
Answer: db.collection.insertOne()
insertOne() is the standard method for inserting a single document into a collection.
Question 13 of 50
What is the correct syntax to insert multiple documents at once?
A
db.collection.insertMany({...}, {...})
B
db.collection.insertMany([{...}, {...}])
C
db.collection.insertAll([{...}, {...}])
D
db.collection.addMany([{...}, {...}])
Not quite. Try another option.
Answer: db.collection.insertMany([{...}, {...}])
insertMany() accepts an array of documents to insert into the collection.
Question 14 of 50
Which method retrieves all documents from a collection?
A
db.collection.getAll()
B
db.collection.find()
C
db.collection.select(*)
D
db.collection.search()
Not quite. Try another option.
Answer: db.collection.find()
find() without arguments returns a cursor to all documents in the collection.
Question 15 of 50
How do you format the output of a find() query to be more readable in the shell?
A
db.collection.find().beautify()
B
db.collection.find().format()
C
db.collection.find().pretty()
D
db.collection.find().clean()
Not quite. Try another option.
Answer: db.collection.find().pretty()
The .pretty() method formats the resulting JSON output with indentation and line breaks.
Question 16 of 50
Which operator is used to specify fields to include or exclude in a query result (Projection)?
A
WHERE field
B
SHOW field
C
SELECT field
D
{ field: 1 }
Not quite. Try another option.
Answer: { field: 1 }
In the second argument of find(), setting a field to 1 includes it, while 0 excludes it.
Question 17 of 50
Which update operator is used to modify the value of a specific field?
A
$modify
B
$set
C
$change
D
$update
Not quite. Try another option.
Answer: $set
The $set operator replaces the value of a field with the specified value.
Question 18 of 50
What is the difference between updateOne() and updateMany()?
A
updateOne updates the last match; updateMany updates all matches.
B
updateOne updates the first match; updateMany updates all matches.
C
updateMany is deprecated.
D
They function identically.
Not quite. Try another option.
Answer: updateOne updates the first match; updateMany updates all matches.
updateOne affects only the first document matching the filter, while updateMany affects all matching documents.
Question 19 of 50
Which method is used to remove a document from a collection?
A
db.collection.erase()
B
db.collection.deleteOne()
C
db.collection.clear()
D
db.collection.zap()
Not quite. Try another option.
Answer: db.collection.deleteOne()
deleteOne() removes the first document that matches the filter criteria.
Question 20 of 50
What is the default TCP port for MongoDB?
A
5432
B
3306
C
27017
D
8080
Not quite. Try another option.
Answer: 27017
27017 is the standard default port for a MongoDB instance.
Question 21 of 50
In a MongoDB connection string mongodb://localhost:27017/mydb, what does mydb represent?
A
The server name
B
The username
C
The database name
D
The collection name
Not quite. Try another option.
Answer: The database name
The path segment following the host and port in the connection string specifies the database to connect to.
Question 22 of 50
What does ODM stand for in the context of Mongoose?
A
Online Database Manager
B
Object Data Model
C
Object Document Mapper
D
Object Database Method
Not quite. Try another option.
Answer: Object Document Mapper
Mongoose is an ODM (Object Document Mapper) that maps JavaScript objects to MongoDB documents.
Question 23 of 50
Which command installs Mongoose in a Node.js project?
A
npm add mongoose-db
B
npm install mongoose
C
node install mongoose
D
npm install mongo
Not quite. Try another option.
Answer: npm install mongoose
The standard NPM command to install the Mongoose library is npm install mongoose.
Question 24 of 50
In Mongoose, what is a 'Schema'?
A
A direct connection to the database.
B
A configuration object defining the structure and rules of data.
C
The actual document stored in MongoDB.
D
A query builder.
Not quite. Try another option.
Answer: A configuration object defining the structure and rules of data.
A Schema defines the shape of the documents within a collection, including types, defaults, and validation.
Question 25 of 50
Which function is used to create a Mongoose Schema?
A
mongoose.define()
B
new mongoose.Table()
C
mongoose.createSchema()
D
new mongoose.Schema()
Not quite. Try another option.
Answer: new mongoose.Schema()
You define a schema by instantiating new mongoose.Schema({...}).
Question 26 of 50
What is a Mongoose 'Model'?
A
A type of validation rule.
B
A JSON file storing data.
C
A prototype of the database server.
D
A compiled version of the Schema used to interact with the database.
Not quite. Try another option.
Answer: A compiled version of the Schema used to interact with the database.
A Model is a class constructed from a Schema that provides an interface to the database (CRUD operations).
Question 27 of 50
How do you define a model named 'User' based on a schema userSchema?
A
userSchema.model('User')
B
mongoose.createModel('User', userSchema)
C
new mongoose.Model('User', userSchema)
D
mongoose.model('User', userSchema)
Not quite. Try another option.
Answer: mongoose.model('User', userSchema)
mongoose.model() is the method used to create a model from a name and a schema.
Question 28 of 50
In a Mongoose Schema, how do you ensure a field is mandatory?
A
mandatory: true
B
required: true
C
allowNull: false
D
mustHave: true
Not quite. Try another option.
Answer: required: true
The required: true property in a schema definition enforces that the field must be present.
Question 29 of 50
Which method is used to save a new document instance created via Mongoose?
A
document.create()
B
document.save()
C
document.push()
D
document.insert()
Not quite. Try another option.
Answer: document.save()
When you create a new instance of a Model, you call .save() on that instance to persist it to the database.
Question 30 of 50
Which Mongoose method finds a document by its _id?
A
Model.get()
B
Model.findId()
C
Model.findOneId()
D
Model.findById()
Not quite. Try another option.
Answer: Model.findById()
findById(id) is a convenience method provided by Mongoose to retrieve a document by its primary key.
Question 31 of 50
What data type should be defined in a Mongoose schema for an age field?
A
Int
B
Integer
C
Number
D
Float
Not quite. Try another option.
Answer: Number
Mongoose uses standard JavaScript types and specific Mongoose types. Number covers integers and floats.
Question 32 of 50
How do you connect to MongoDB using Mongoose?
A
mongoose.connect(connectionString)
B
mongoose.start(connectionString)
C
mongoose.open(connectionString)
D
mongoose.db.connect(connectionString)
Not quite. Try another option.
Answer: mongoose.connect(connectionString)
mongoose.connect() is the method used to establish a connection to the MongoDB instance.
Question 33 of 50
Which query operator is used in MongoDB to find values 'greater than' a specific value?
A
$gt
B
$lt
C
$high
D
$gte
Not quite. Try another option.
Answer: $gt
$gt stands for 'greater than'.
Question 34 of 50
What is the purpose of Model.create() in Mongoose?
A
To create a collection only.
B
To instantiate and save a document in one step.
C
To define a schema.
D
To create a database index.
Not quite. Try another option.
Answer: To instantiate and save a document in one step.
Model.create(data) is a shortcut for creating a new instance and calling .save() immediately.
Question 35 of 50
When defining a schema, what does default: Date.now do?
A
Forces the user to enter the current date.
B
Throws an error if the date is not now.
C
Updates the date every time the document is accessed.
D
Sets the field to the current date if no value is provided.
Not quite. Try another option.
Answer: Sets the field to the current date if no value is provided.
The default property specifies a value (or function returning a value) to use if the field is missing during creation.
Question 36 of 50
Which Mongoose method is used to find a document by ID and update it?
A
findByIdAndUpdate
B
saveById
C
findAndModify
D
updateById
Not quite. Try another option.
Answer: findByIdAndUpdate
findByIdAndUpdate finds a matching document, updates it according to the update object, and optionally returns the new or old document.
Question 37 of 50
In the MongoDB shell, what does db refer to?
A
The database server
B
The admin user
C
The current database context
D
The collection list
Not quite. Try another option.
Answer: The current database context
The variable db in the shell refers to the database currently selected via the use command.
Question 38 of 50
What is the result of db.collection.find({ age: 25 })?
A
Deletes documents where age is 25.
B
Updates documents where age is 25.
C
Returns all documents where age is 25.
D
Returns the first document where age is 25.
Not quite. Try another option.
Answer: Returns all documents where age is 25.
find with a query object returns a cursor for all documents matching the criteria.
Question 39 of 50
Which of the following is NOT a valid BSON data type?
A
Table
B
String
C
Array
D
Boolean
Not quite. Try another option.
Answer: Table
Table is a relational database concept; it is not a BSON data type. BSON supports Arrays, Strings, Booleans, Objects, etc.
Question 40 of 50
What does the limit() method do in a MongoDB query?
A
Limits the number of fields returned.
B
Stops the query after a specific time.
C
Restricts the size of the document.
D
Specifies the maximum number of documents to return.
Not quite. Try another option.
Answer: Specifies the maximum number of documents to return.
Appended to a find() query, limit(n) ensures only n documents are returned.
Question 41 of 50
In Node.js, most MongoDB operations are:
A
Linear
B
Asynchronous
C
Synchronous
D
Blocking
Not quite. Try another option.
Answer: Asynchronous
Database operations in Node.js (via driver or Mongoose) are asynchronous and return Promises or use callbacks.
Question 42 of 50
Which Mongoose schema option adds createdAt and updatedAt fields automatically?
A
{ timestamps: true }
B
{ stamps: true }
C
{ dates: true }
D
{ time: true }
Not quite. Try another option.
Answer: { timestamps: true }
Passing { timestamps: true } as the second argument to the Schema constructor automatically manages creation and update timestamps.
Question 43 of 50
What is the purpose of the unique: true option in a Mongoose schema field?
A
It ensures the field cannot be null.
B
It makes the field read-only.
C
It hides the field from queries.
D
It creates a unique index to prevent duplicate values for that field.
Not quite. Try another option.
Answer: It creates a unique index to prevent duplicate values for that field.
unique: true tells MongoDB to create a unique index, ensuring no two documents have the same value for that field.
Question 44 of 50
Which method effectively removes a document by ID in Mongoose?
A
findByIdAndRemove() (or findByIdAndDelete)
B
deleteId()
C
removeById()
D
dropId()
Not quite. Try another option.
Answer: findByIdAndRemove() (or findByIdAndDelete)
findByIdAndDelete (and the older findByIdAndRemove) is used to find a document by its ID and remove it from the collection.
Question 45 of 50
What is the structural difference between SQL and NoSQL regarding schemas?
A
SQL has rigid schemas; NoSQL has dynamic/flexible schemas.
B
SQL has dynamic schemas; NoSQL has rigid schemas.
C
Both use rigid schemas.
D
Both use dynamic schemas.
Not quite. Try another option.
Answer: SQL has rigid schemas; NoSQL has dynamic/flexible schemas.
SQL requires a predefined table structure. MongoDB (NoSQL) allows documents in the same collection to have different fields (though Mongoose enforces a schema at the application level).
Question 46 of 50
To perform an update that increments a number field by 1, which operator is used?
A
$inc
B
$add
C
$plus
D
$sum
Not quite. Try another option.
Answer: $inc
The $inc operator increments a field by a specified value.
Question 47 of 50
What does the findOne method return if no document matches?
A
An error
B
An empty array []
C
null
D
undefined
Not quite. Try another option.
Answer: null
findOne returns a single document object if found, or null if no match is found.
Question 48 of 50
Which file usually contains the database connection logic in a Node/Express app?
A
package.json
B
db.js or app.js
C
style.css
D
index.html
Not quite. Try another option.
Answer: db.js or app.js
Backend logic, including database connections, is typically found in the main application file (app.js, server.js) or a dedicated config file (db.js).
Question 49 of 50
In a Mongoose query, how do you specify that you want to sort the results in descending order?
A
.order('down')
B
.sort({ field: 1 })
C
.sort({ field: 'desc' })
D
.sort({ field: -1 })
Not quite. Try another option.
Answer: .sort({ field: -1 })
In MongoDB/Mongoose sorting, 1 represents ascending order and -1 represents descending order.
Question 50 of 50
If you want to define an array of strings in a Mongoose schema, what is the correct syntax?
A
tags: String[]
B
tags: [String]
C
tags: Array<String>
D
tags: { type: Array, contains: String }
Not quite. Try another option.
Answer: tags: [String]
Mongoose uses the syntax [String] (or [Number], etc.) to define an array of a specific type.