Interview question of mongoDB set 2/MongoDB Interview Questions and Answers for Freshers & Experienced

What happens when the Shard is slow or down while querying?

When the Shard is slow, the query returns an error until partial query options are fixed. When the shard is reacting slowly, MongoDB waits for it.

Posted Date:- 2021-08-31 08:37:21

How do we configure the cache size in MongoDB?

In MongoDB, we cannot configure the cache. MongoDB utilizes the free spaces over the system automatically by using memory-mapped files.

Posted Date:- 2021-08-31 08:36:39

How do we perform the Join operations in MongoDB?

From MongoDB3.2, we can perform the Join operation. The new $lookup operator included with the aggregation pipeline is the same as the left outer join. Example:

from: <collection to join>,
localField: <field from the input documents>,
foreignField: <field from the documents of the "from" collection>,
as: <output array field>

Posted Date:- 2021-08-31 08:35:53

Does MongoDB require plenty of RAM?

No, MongoDB does not require plenty of RAM. It can run on a small amount of memory. MongoDB dynamically assigns and unassigns RAM according to the needs of other processes.

Posted Date:- 2021-08-31 08:35:06

What are the elements of the Sharded Cluster?

Following are the elements of the Sharded Cluster:

1. Query routers
2. Shards
3. Config servers

Posted Date:- 2021-08-31 08:34:01

Explain Vertical Scaling and Horizontal Scaling?

<> Vertical Scaling: Vertical Scaling increases storage and CPU resources for expanding the capacity.

<> Horizontal Scaling: Horizontal Scaling splits the datasets and circulates the data over multiple shards or servers.

Posted Date:- 2021-08-31 08:32:57

What does ObjectId contain?

ObjectId contains the following:

1. Client machine ID
2. Client process ID
3. Byte incremented counter
4. Timestamp

Posted Date:- 2021-08-31 08:32:07

What are the points we should consider while creating a schema in MongoDB?

We must consider the following points while creating a schema:

< Designing the Scheme based on the user requirements.
< Combining the objects into one document, if we have to use them jointly, or else, separate them.
< Perform joins while on write, and not while it is on reading.
< For most general application scenarios, maximize the schema.
< Perform complex aggregations in the schema.

Posted Date:- 2021-08-31 08:30:57

Why do we use the pretty() method?

We use the pretty() method for displaying the results in a formatted way.

Posted Date:- 2021-08-31 08:28:27

Which command we use for dropping a database?

We use the “DB.drop database” command for dropping a database.

Posted Date:- 2021-08-31 08:27:38

How do you refer to the current database in a statement? (by using db)

Current database is referred to as ‘db’. Example – db.collection.find();

Posted Date:- 2021-08-31 08:26:57

Explain the procedure of starting the MongoDB server/ instance?

To start a MongoDB instance, follow the steps as below:

> First, open the command prompt and run mongod.exe.
> Alternatively, you can move to the path where MongoDB is installed, for example, “C: MongoDB”
> Navigate to the bin folder, locate the mongod.exe and double click the same to execute it.
> You can also navigate to the required folder, for example, “C: MongoDB/bin” and type mongo to connect MongoDB through the shell.

Posted Date:- 2021-08-31 08:26:10

Which command we use for creating the backup of the database?

We use the mongodump command for creating the database backup.

Posted Date:- 2021-08-31 08:24:56

What is the syntax of the skip() method?

skip() method syntax is:


Posted Date:- 2021-08-31 08:24:17

How do we create a database in MongoDB?

When I want to create a database in MongoDB, I faced the following error:


MongoDB shell version:1.65

Connecting to: test

Error: Could not connect to the server

Exception: connect failed

The solution to the above error:

We remove the mongod. lock from the folder
Sudo start MongoDB

Posted Date:- 2021-08-31 08:22:59

Define oplog(operational log)?

Operational log(oplog) is a special kind of limited collection that stores a rolling record of all the operations which change the data we store in our databases. Primarily, it applies all the database operations over the primary and, after that, records these operations on the oplog of the primary. After that, the secondary members replicate and apply the operations in the asynchronous process.

Posted Date:- 2021-08-31 08:22:22

How do we perform sorting and Explain Project in MongoDB?

For finding any data in MongoDB, we use the find() method. The discovery () method returns the collection’s documents over which we invoked this method. We can use the “Where” clause in the MongoDB query in order to restrict the output by using MongoDB projection. Anytime we execute the find() method, MongoDB returns all the documents associated with a particular collection.

db.<collection_name>.find({ }, {<key_Name>:<Flag to display>})

Posted Date:- 2021-08-31 08:20:14

What is the difference between a secondary and a slave?

A secondary is a node/member that uses the existing primary’s operations. This is accomplished by following the replication oplog ( The replication from primary to secondary is asynchronous; however, the secondary will strive to keep up with the primary as much as practicable (on a LAN, this is often a few milliseconds).

Posted Date:- 2021-08-31 08:19:40

What exactly is journaling, and how does it function?

MongoDB maintains data integrity by creating an on-disk journal for each write. In the event of a server failure, the log will be used to detect writes that were not written to the disk or data files.

Posted Date:- 2021-08-31 08:18:59

What is the significance of a covered query?

Since the index contains all of the fields, MongoDB will fit the question condition and return the result fields without having to search into the documents. Since indexes are contained in RAM or sequentially on disk, such access is much quicker.

Posted Date:- 2021-08-31 08:15:52

Does an update fsync to the disk immediately?

No, it does not. By default, disk writes are lazy. A write cannot reach the disk for many seconds. For example, if the database receives a thousand increments to an object in one second, the object can only be flushed to disk once (it should be noted that fsync options are accessible both at the command line and via getLastError_old).

Posted Date:- 2021-08-31 08:14:49

What is the structure of ObjectId?

It is made up of the following components:

1. Client process ID
2. Timestamp
3. Client machine ID
4. Byte incremented counter

Posted Date:- 2021-08-31 08:14:17

What is the purpose of the DB command?

We use the “DB” command to get the name of the presently selected database.

Posted Date:- 2021-08-31 08:13:08

What is the purpose of the save() method?

We use the save() method for replacing the existing documents with new documents.

Posted Date:- 2021-08-31 08:12:39

Explain Splitting?

Splitting is the background process that we use to store chunks from increasing too large.

Posted Date:- 2021-08-31 08:12:08

Can MongoDB Support foreign key constraints?

No, MongoDB doesn’t support foreign key constraints. Because of the document structure, MongoDB provides flexible ways to define relationships.

Posted Date:- 2021-08-31 08:11:38

What are the commands to create a backup of the data and restore the data?

Use the command mongodump to create a backup.

Use the command mongorestore [backup_path] to restore the data.

Posted Date:- 2021-08-31 08:11:06

What is the importance of profiler in MongoDB?

MongoDB contains the database profiler that shows the performance characteristics of every operation against the database. Through the profiler, we can identify the queries that are slower than they should be and use this data to determine when we require an index.

Posted Date:- 2021-08-31 08:10:34

Explain Sharding and Aggregation in MongoDB?

a) Aggregation: Aggregations are the activities that handle the data records and give the record results.
b) Sharding: Sharding means storing the data on multiple machines.

Posted Date:- 2021-08-31 08:10:12

How does MongoDB provides concurrency?

MongoDB utilizes the reader-writer locks, enabling concurrent readers to access any supply such as collection or database though it provides private access to individual writers.

Posted Date:- 2021-08-31 08:09:38

How to do Journaling in MongoDB?

We save the write operations in the memory while journaling is taking place. The on-disk journal files are dependable for the reason that journal writers are usual. In the DB path, MongoDB designs a journal subdirectory.

Posted Date:- 2021-08-31 08:09:11

How to do locking or transactions in MongoDB?

MongoDB does not use traditional locking with the reduction because it is high-speed, knowable, and light in the presentation. We can consider it as the MyISAM, MySQL auto entrust script. Through the simpler business sustain, we can enhance the performance, specifically in the structure with various servers.

Posted Date:- 2021-08-31 08:08:44

What is the importance of GridFS and Journaling?

1. GridFS: We use GridFS to retrieve and store large files like images, videos, and audio files.
2. Journaling: We use Journaling for secure backups in MongoDB.

Posted Date:- 2021-08-31 08:08:11

In MongoDB, how are constraints managed?

Starting with MongoDB 3.2, you can add a document validator to collections. Unique indexes can also be formed using db.collection. createIndex(“key”: 1, );

Posted Date:- 2021-08-31 08:07:17

What factors should be considered while constructing a schema in MongoDB?

The following points must be considered:

> Create the schema in accordance with the needs of the users.
> If you use several objects together, combine them into a single document. Separate them if necessary.
> Do joins while writing, not while reading.
> Optimize the schema with the most common use cases.
> In the schema, perform complex aggregation.

Posted Date:- 2021-08-31 08:06:58

What language is MongoDB written in?

MongoDB is written and coded in C++.

Posted Date:- 2021-08-31 08:06:14

Compare MongoDB with Couchbase and CouchbaseDB.

While MongoDB, Couchbase and Couchbase DB have several similarities, they vary in terms of model execution requirements, crossing points, storage, duplications and so on.

Posted Date:- 2021-08-31 08:05:56

Are null values permitted?

Yes, it’s only for the members of an object. Since a null is not an object, it cannot be attached to the database collection. However, {} can be added.

Posted Date:- 2021-08-31 08:05:38

How do you see the connections used by Mongos?

The following command needs to be used: db._adminCommand(“connPoolStats”);

Posted Date:- 2021-08-31 07:48:57

How can applications access real-time data changes in MongoDB?

Applications can access real-time data changes using Change streams which acts as a subscriber to all the collection operations like insert, delete and update.

Posted Date:- 2021-08-31 07:46:06

What is the replication mechanism in MongoDB?

The process of synchronizing data through several servers is known as replication. With several copies of data on various database servers, it offers continuity and increases data efficiency. Replication protects the database from the loss of a single server.

Posted Date:- 2021-08-31 07:45:42

“When you add more slaves to a replica set, both writes and reads become faster.” Is this claim correct or incorrect? Why is this so?

False. All write operations are only performed on the master. Read operations, on the other hand, may be performed on any instance — slave or master. As more slaves are added to a replica set, only reads get faster.

Posted Date:- 2021-08-31 07:45:13

Is it essential for MongoDB to have a ton of RAM?

No, it does not. MongoDB does not need a ton of RAM to operate. It can operate on very little RAM because it dynamically allocates and deallocates RAM based on the needs of the processes.

Posted Date:- 2021-08-31 07:43:55

When and to what degree does data become multi-slice?

MongoDB scrap stands on a collection. As a result, an album containing all substances is stored in the form of a lump or mass. Where an extra time period is available there can be more than a few slice data accomplishment options, so when there is more than one chunk, data is extended to a large number of slices and can be extended to 64 MB.

Posted Date:- 2021-08-31 07:43:38

Is an object attribute deleted from the store as it is removed?

Yes, you can erase the attribute and then re-save() the object.

*Basic MongoDB interview questions like these are quite frequently asked to test the basic knowledge of the candidate.

Posted Date:- 2021-08-31 07:43:16

In MongoDB, how do you use the primary key?

In MongoDB, the _id field is reserved for the primary key, and it has a unique value. If you don’t specify anything for _id, it will be filled with “MongoDB Id Object.” However, you can enter some unique information in that field.

Posted Date:- 2021-08-31 07:42:55

MongoDB is referred to as a schema-less database. Is this true? How can you make a schema in MongoDB?

Since JSON is a schema-free data system, it will be more accurate to assume that MongoDB has a dynamically typed schema. Create and insert a text to begin creating a schema. When a document is entered into the database, a corresponding collection is generated.

Posted Date:- 2021-08-31 07:40:35

List some of the data types supported by MongoDB.

Some data types are Numbers, String, Array, Binary data, Boolean, Date, Regular expressions, ObjectId, etc…

Posted Date:- 2021-08-31 07:40:16

Is it possible to establish primary key – foreign key relationships in MongoDB?

By embedding one document within another, we may achieve a primary key-foreign key relationship. For instance, an address document may be inserted inside a customer document.

Posted Date:- 2021-08-31 07:39:40

What are the main distinctions between BSON documents in MongoDB and JSON documents in general?

JSON (JavaScript Object Notation), like XML, is a human-readable data exchange standard. JSON has been the most commonly adopted data exchange standard on the web. JSON accepts booleans, numbers, sequences and arrays as data types. BSON, on the other hand, is the binary encoding used by MongoDB to store its documents. It is equivalent to JSON, but it expands JSON to accept additional data types, such as Date. Unlike JSON records, BSON documents are ordered. BSON usually uses less room than JSON and traverses easier. Since it is binary, BSON is, therefore, faster to encrypt and decode.

Posted Date:- 2021-08-31 07:39:03

R4R Team
R4R provides MongoDB Freshers questions and answers (MongoDB Interview Questions and Answers) .The questions on website is done by expert team! Mock Tests and Practice Papers for prepare yourself.. Mock Tests, Practice Papers,Interview question of mongoDB set 2,MongoDB Freshers & Experienced Interview Questions and Answers,MongoDB Objetive choice questions and answers,MongoDB Multiple choice questions and answers,MongoDB objective, MongoDB questions , MongoDB answers,MongoDB MCQs questions and answers R4r provides Python,General knowledge(GK),Computer,PHP,SQL,Java,JSP,Android,CSS,Hibernate,Servlets,Spring etc Interview tips for Freshers and Experienced for MongoDB fresher interview questions ,MongoDB Experienced interview questions,MongoDB fresher interview questions and answers ,MongoDB Experienced interview questions and answers,tricky MongoDB queries for interview pdf,complex MongoDB for practice with answers,MongoDB for practice with answers You can search job and get offer latters by studing .learn in easy ways .