Mongo DB
Mongo DB
for its flexibility, scalability, and ease of use. It belongs to the document-oriented
and concepts:
documents can vary in structure and can contain arrays and other nested
documents.
doesn't require a predefined schema for the data it stores. This provides
allows for data processing and analysis within the database itself. It supports
data to be replicated across multiple servers for fault tolerance and high
across multiple servers to distribute the load and improve scalability. This
providing resources, tutorials, and support for users. It also has a rich
ecosystem with libraries, frameworks, and tools for integration with various
mobile, IoT, and big data, where flexibility, scalability, and performance are key
requirements.
In MongoDB, a database is created implicitly when you first create a collection within
that database. MongoDB does not require you to explicitly create a database before
using it. When you insert data into a collection within a database that doesn't exist yet,
MongoDB automatically creates the database and the collection.
However, if you want to explicitly create a new database, you can use the use command
followed by the name of the database you want to create. Here's how you can do it
using the MongoDB shell:
use my_database
Replace my_database with the name you want to give to your database. If the database
already exists, MongoDB will switch to that database. If the database doesn't exist,
MongoDB will create it.
It's important to note that until you create at least one document within a collection in
the database, the database itself won't be visible in the list of databases. This is because
MongoDB creates databases and collections only when they are needed. Once you
insert data into a collection, the database and collection will be visible in the MongoDB
shell or any other MongoDB client.
In MongoDB, you interact with data primarily through collections, which are
analogous to tables in relational databases. Here's a brief overview of how you can
1. Inserting Documents: To insert a document into a collection, you can use the
called users:
});
a filter to identify the document(s) to be updated and provide the new values
users collection:
users collection:
db.users.find();
offers many more advanced features for querying, indexing, aggregation, and
db.employees.find({});
12-31") } });
12.Retrieve documents where department is either "IT" or "HR":
1000) } });
"IT":
20.Retrieve documents where email is provided and hire date is within the last
year:
"$salary" } } } ]);
"$salary" } } } ]);
"$salary" } } } ]);
"$hiredate" } } } ]);
7. Calculating Salary Range for Each Department (difference between max and
min salary):
db.employees.aggregate([ { $group: { _id: "$department", minSalary: { $min:
Each Department:
Here are 30 multiple-choice questions (MCQs) along with their answers based on
d) A key-value store
a) insertOne()
b) insert()
c) addOne()
d) create()
Answer: a) insertOne()
a) Vertical scaling
b) Horizontal scaling
c) Diagonal scaling
d) Linear scaling
a) $gt
b) $lt
c) $gte
d) $lte
Answer: a) $gt
MongoDB?
a) $avg
b) $sum
c) $max
d) $min
Answer: a) $avg
a) updateOne()
b) modify()
c) change()
d) replaceOne()
Answer: a) updateOne()
a) XML
b) CSV
c) JSON
d) YAML
Answer: c) JSON
a) $or
b) $not
c) $and
d) $nor
Answer: c) $and
a) Sorting
b) Filtering
c) Grouping
a) delete()
b) deleteOne()
c) remove()
d) deleteMany()
Answer: d) deleteMany()
a) $in
b) $regex
c) $like
d) $pattern
Answer: b) $regex
a) Data loss
b) Data integrity
c) Data consistency
d) Data compression
a) findOne()
b) getOne()
c) fetchOne()
d) retrieveOne()
Answer: a) findOne()
What does MongoDB use to distribute data across multiple servers for scalability?
a) Replication
b) Sharding
c) Clustering
d) Partitioning
Answer: b) Sharding
MongoDB?
a) $gt
b) $lt
c) $gte
d) $lte
Answer: d) $lte
a) Data insertion
b) Data updating
c) Data querying
d) Data aggregation
b) removeOne()
c) eraseOne()
d) destroyOne()
Answer: a) deleteOne()
a) Primary indexing
b) Secondary indexing
c) Tertiary indexing
d) Quaternary indexing
b) updateMany()
c) modifyMany()
d) changeMany()
Answer: b) updateMany()
b) Documents
c) Fields
d) Databases
Answer: c) Fields
a) fetchAll()
b) retrieveAll()
c) find()
d) getAll()
Answer: c) find()
b) Horizontal scaling
c) Diagonal scaling
d) Linear scaling
a) Sorting
b) Filtering
c) Projecting fields
d) Grouping
a) remove()
b) deleteAll()
c) deleteMany()
d) deleteAllDocuments()
Answer: c) deleteMany()
b) MapReduce
c) Joins
d) Transactions
Answer: b) MapReduce
a) Sorting
b) Filtering
d) Grouping