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

Can the old files in the ‘moveChunk’ directory be removed?

Yes, these files are made as backups during normal Shard balancing operations. Once the operations are done then they can be deleted. The clean-up process is currently manual so this needs to be taken care of to free up space.

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

What happens when a Shard is down or slow when querying?

If a Shard is down, the query will return an error unless the ‘Partial’ query options is set. If a shard is responding slowly, Mongos will wait for it.

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

What happens when a document is updated on a chunk that is being migrated?

The update will go through immediately on the old Shard and then the change will be replicated to the new Shard before ownership transfers.

Posted Date:- 2021-08-31 07:34:15

When will data be on more than one Shard?

MongoDB Sharding is range-based. So all the objects in a collection lie into a chunk. Only when there is more than 1 chunk there is an option for multiple Shards to get data. Right now, the default chunk size is 64mb, so you need at least 64mb for migration.

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

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 07:32:39

Does MongoDB write to disk automatically or slowly?

MongoDB writes data to disk in a haphazard fashion. It changes the data that is automatically written to the server, but it writes the data from the journal to disk slowly.

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

What have capped collections?

Capped collections are fixed-size collection and insert and retrieve data based on insertion order. If a collection’s space is full, the oldest records will be overwritten by the new documents in the collection.

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

How does concurrency affect primary replica set?

When the collection changes are written to primary, MongoDB writes the same to a special collection in the local database, called the primary’s oplog. Hence, both the collection’s database and local database are locked.

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

State the difference between find() and limit() method.

find() – displays only selected data rather than all the data of a document. For example, if your document has 4 fields but you want to show only one, set the required field as 1 and others as 0.

limit() – limit function limits the number of records fetched. For example, if you have 7 documents but want to display only the first 4 documents in a collection, use limit. Syntax –


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

Explain aggregation in MongoDB.

Aggregation groups values from different documents and performs operations on the data to return a single result. There are 3 ways in which MongoDB performs aggregation –

Aggregation pipeline
Map-reduce function
Single purpose aggregation methods

Posted Date:- 2021-08-31 07:27:15

What are MongoDB’s data models?

The structure of documents influences data modeling. Related data in MongoDB may be embedded in a single document structure (embedded data model). Through references from one document to another, the relationship between data is stored. It is called the normalized data model.

Posted Date:- 2021-08-31 07:26:33

How do you see the Mongos connection?

To see the connection used by Mongodb, use db adminCommand (“connPoolStats”);

Posted Date:- 2021-08-31 07:25:58

On a high level, compare SQL databases and MongoDB.

SQL databases store data in the form of tables, rows, columns and documents. This data is contained in a pre-defined data format, which is not quite scalable for today’s rapidly increasing real-world applications. MongoDB, on the other hand, employs a modular framework that can be quickly changed and expanded.

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

How does MongoDB handle transactions and locks?

MongoDB uses multi-granularity locking wherein operations can be locked at the global, database or collection level. It is up to the storage engines to implement the level of concurrency. For example, in WiredTiger, it is at document-level. For reads, there is a shared locking mode, while for write there is an exclusive locking mode

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

Explain the role of profiler in MongoDB.

A profiler is an in-built tool that finds out the slow and resource-intensive queries and provides query-level insights. You as a dba can analyze the queries. Profiler stores all the data in system.profile collection.

Posted Date:- 2021-08-31 07:23:49

What is a replica set?

We can specify the replica as a set of the mongo instances which host a similar data set. In the replica set, one node will be primary, and another one will be secondary. We replicate all the data from the primary to the secondary nodes.

Posted Date:- 2021-08-31 07:23:20

What are the similarities and differences between sharding and replication in MongoDB?

Both sharding and replication require the use of several instances to host the database. Replicas are MongoDB instances that contain identical data, hence the name. To maximize redundancy and availability, we use replicas. In contrast, for sharding, each shard instance has data that is distinct from its neighbors. For horizontal scaling, we use sharding.

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

What are the various languages that MongoDB supports?

MongoDB officially supports the following languages: C, C++, C#, Java, Node.js, Perl, PHP, Python, Ruby, Scala, Go and Erlang. MongoDB can be used for any of the languages mentioned above. There are several other community-supported drivers, but the ones mentioned above are given by MongoDB.

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

What is an ACID transaction? Does MongoDB support it?

ACID stands for Atomicity, Consistency, Isolation, and Durability. The transaction manager ensures these attributes are taken care of. Yes, MongoDB version 4.0 supports ACID.

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

Explain the significance of the covered query?

A covered query makes the query implementation quicker as we store the indexes in the RAM or consecutively located on the disk. It makes query execution quicker. The covered query covers all the fields in the index, MongoDB matches the query condition along with returning the result fields.

Posted Date:- 2021-08-31 07:19:10

Why MongoDB is the best NoSQL database?

MongoDB is the best NoSQL database due to the following features:

>> High Performance
>> High Availability
>> Easily Scalable
>> Rich Query Language
>> Document Oriented

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

Explain about Indexes in MongoDB?

In MongoDB, we use Indexes for executing the queries efficiently; without using Indexes, MongoDB should carry out a collection scan, i.e., scan all the documents of a collection, for selecting the documents which match the query statement. If a suitable index is available for a query, MongoDB will use an index for restricting the number of documents it should examine.

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

What’s a Master or Primary?

This is a node/member which is currently the primary and processes all writes for the replica set. During a failover event in a replica set, a different member can become primary.

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

How long does replica set failover take?

It may take 10-30 seconds for the primary to be declared down by the other members and a new primary to be elected. During this window of time, the cluster is down for primary operations i.e writes and strong consistent reads. However, eventually consistent queries may be executed to secondaries at any time (in slaveOk mode), including during this window.

Posted Date:- 2021-08-31 07:15:49

Why are data files so large?

MongoDB does aggressive preallocation of reserved space to avoid file system fragmentation.

Posted Date:- 2021-08-31 07:15:18

How do I do transactions/locking?

MongoDB does not use traditional locking or complex transactions with rollback, as it is designed to be light weight, fast and predictable in its performance. It can be thought of how analogous is to the MySQL’s MyISAM autocommit model. By keeping transaction support extremely simple, performance is enhanced, especially in a system that may run across many servers.

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

Does an update fsync to disk immediately?

No. Writes to disk are lazy by default. A write may only hit the disk a couple of seconds later. For example, if the database receives thousand increments to an object within one second, it will only be flushed to disk once. (Note: fsync options are available both at the command line and via getLastError_old.)

Posted Date:- 2021-08-31 07:14:09

In what ways is MongoDB better than MySQL? Explain.

MongoDB has a flexible data model wherein the schema can be expanded based on business needs. Also, MongoDB is faster and can handle more data types to manage real-time applications better.

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

How are sharding and replication similar to each other in MongoDB, and how are they different?

Both sharding and replication involve using more than one instance to host the database.

Replicas are MongoDB instances with the same data, hence the name. We use replicas to increase redundancy and availability.

With sharding, on the other hand, each shard instance has different data from its neighbors. We use sharding for horizontal scaling.

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

Name the 2 storage engines using MongoDB?

MMAPv1 and WiredTiger are the 2 storage engines used by MongoDB.

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

What is a covered query and why is it important?

In a covered query, all the fields used in the query have the index created. The results returned should also be part of the index. Due to this, MongoDB fetches the results without actually looking inside documents, thus saving time and increasing efficiency.

Posted Date:- 2021-08-31 07:09:15

What is sharding in MongoDB?

MongoDB meets the data growth using Sharding, which means sorting data records across various machines. Each shard is a replica set.

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

Name the default index created for a new collection.

Default index created for the new collection is _id

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

How can you query real-time MongoDB data?

Using the utilities mentioned can help handle live MongoDB data.

MongoHub has been migrated to a native Mac version.
This comes in handy with tree and document views.
Genghisapp – this is a web-based GUI that is clean, light-weight, easy to use, has keyboard shortcuts and performs fantastically well. GridFS is also supported.

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

What is BSON?

BSON or binary JSON is the binary encoded format of JSON. It extends JSON and provides more data types and fields.

Posted Date:- 2021-08-31 07:04:50

What is ObjectId? How is it structured?

ObjectId is a class which is the default primary key for the document in MongoDB. It is found in the _id field of the inserted document. It is a 12-byte BSON type generated using a default algorithm. The structure is –
A 4-byte value that represents seconds since Unix epoch
3-byte machine id
2-byte process id
3-bytes counter that starts with a random number

Posted Date:- 2021-08-31 07:04:24

How are constraints managed in MongoDB?

You can add document validator on the collections starting MongoDB 3.2. Unique indexes can also be created using db.collection.createIndex({“key” : 1} , );

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

How do you perform CRUD operations in MongoDB?

<> C – Create – db.collection.insert();
<> R – Read – db.collection.find();
<> U – Update – db.collection.update();
<> D – Delete – db.collection.remove({“fieldname” : ”value”});

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

MongoDB is called a schema-less database. Is it true? How to create the schema in MongoDB?

It would be more appropriate to say that MongoDB has dynamically typed schema because it relies on JSON which is a schema-free data structure. To create a schema, create and insert a document. Once a document is inserted, a corresponding collection will be created in the database.

Posted Date:- 2021-08-31 07:01:50

How is data stored in MongoDB?

Since MongoDB is document-based, data is stored in BSON or Binary JavaScript Object Notation, which is the binary-encoded format of JSON.

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

What are 32-bit nuances?

With journaling, there is an additional memory-mapped file activity. This would also restrict the restricted database size of 32-bit builds. Journaling is now disabled by default on 32-bit computers.

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

What specifically is a collection in MongoDB?

A group of documents is referred to as a collection. If a document is the MongoDB analog of a row in a relational database, then a collection is the MongoDB analog of a table.

Dynamic schemas exist in collections. This indicates that the documents included inside a single collection may be of any shape. It’s worth noting that the previous documents’ values are not just of different types (string and integer), but they often have completely different keys. Any document can be added to any collection in MongoDB.

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

Differentiate MongoDB and MySQL?

Despite MySQL and MongoDB are freeware and open source databases, there are several differences between them in terms of a data relationship, transaction, performance speed, querying data, schema design, normalization, etc. Comparison between MongoDB and MySQL is similar to the comparison between Non-relational and Relational databases.

Posted Date:- 2021-08-31 06:57:42

What type of NoSQL database MongoDB is?

MongoDB is a document-oriented database. It stores the data in the form of the BSON structure-oriented databases. We store these documents in a collection.

Posted Date:- 2021-08-31 06:56:51

What is a storage engine? What are the different types of storage engines available in MongoDB?

The storage engine is the database part in charge of handling how data is processed, both in memory and on disk. MongoDB accepts many storage engines since various engines are best suited to different workloads.

<> The default storage engine is the WiredTiger storage engine. It is suitable for the majority of workloads and is recommended for modern implementations. WiredTiger includes, among other things, a document-level concurrency model, checkpointing and compression.
<> MongoDB Enterprise has an in-memory storage engine. It keeps records in memory rather than on disks for more predictable storage latencies.
<> MMAPv1 storage engine is discontinued as of MongoDB v4.0, but it was the default storage engine for MongoDB versions 3.0 and earlier.

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

What type of NoSQL database is MongoDB?

It is a document database that contains documents having key-value pairs, key-array pairs, and nested documents.

Posted Date:- 2021-08-31 06:52:32

How does MongoDB store data?

Being document-based, MongoDB stores documents in BSON or Binary JavaScript Object notation which is the binary encoded format of JSON.

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

What is Mongo shell?

Mongo shell is a JavaScript interface to MongoDB that can be used to query and update data. It is interactive and can also be used to do administrative operations.

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

What are the features of MongoDB?

Following are the important features of MongoDB:

1. A compliant data model in the format of documents.
2. Agile and extremely scalable database.
3. Quicker than traditional databases.
4. Demonstrative query language.

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

What is MongoDB?

MongoDB is a cross-platform document-based database. Categorized as a NoSQL database, MongoDB avoids the conventional table-oriented relational database structure in support of the JSON-like documents with the dynamic schemas, making the data integration in specific kinds of applications quicker and simpler.

MongoDB was developed by a software company “10gen”, in October 2007 as an element of the planned platform as the service product. After that, the company was shifted to a freeware deployment model in 2009, providing sales assistance and other services.

Posted Date:- 2021-08-31 06:50:10

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 1,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 .