80+ Mongodb Interview Questions And Answers 2020

Spread the love

Table of Contents

Mongodb Interview Questions And Answers For Freshers & Experienced 2020

What are NoSQL databases? What are the several types of NoSQL databases?

A NoSQL database offers a mechanism for storage and retrieval of information that’s modeled in means aside from the tabular relations utilized in relational databases (like SQL, Oracle, and so on.).

Types of NoSQL databases:

  • Document Oriented
  • Key Value
  • Graph
  • Column Oriented

What type of NoSQL database MongoDB is?

MongoDB is a doc oriented database. It shops knowledge within the type of BSON construction primarily based paperwork. These paperwork are saved in a group.

Which are crucial options of MongoDB?

  • Flexible knowledge mannequin in type of paperwork
  • Agile and extremely scalable database
  • Faster than conventional databases
  • Expressive question language

What is a Namespace in MongoDB?

A Namespace is the concatenation of the database title and assortment title. For e.g. college.college students with college because the database and college students as the gathering

Which all languages can be utilized with MongoDB?

Currently, MonggoDB offers official driver assist for C, C++, C#, Java, Node.js, Perl, PHP, Python, Ruby, Scala, Go and Erlang. MongoDB can simply be used with any of those languages. There are another neighborhood supported drivers too however the above talked about ones are formally supplied by MongoDB.

Mongodb Interview Questions

Compare SQL databases and MongoDB at a excessive degree

SQL databases retailer knowledge in type of tables, rows, columns and data. This knowledge is saved in a pre-defined knowledge mannequin which isn’t very a lot versatile for right now’s real-world extremely rising purposes. MongoDB in distinction makes use of a versatile construction which could be simply modified and prolonged.

How is MongoDB higher than different SQL databases?

MongoDB permits a extremely versatile and scalable doc construction. For e.g. one knowledge doc in MongoDB can have 5 columns and the opposite one in the identical assortment can have ten columns. Also, MongoDB database are quicker as in comparison with SQL databases as a result of environment friendly indexing and storage methods.

Compare MongoDB and CouchDB at excessive degree

Although each of those databases are doc oriented, MongoDB is a better option for purposes which want dynamic queries and good efficiency on a really huge database. On the opposite facet, CouchDB is healthier used for purposes with sometimes altering queries and pre-defined queries.

Does MongoDB assist international key constraints?

No. MongoDB doesn’t assist such relationships.

Does MongoDB assist ACID transaction administration and locking functionalities?
No. MongoDB doesn’t assist default multi-document ACID transactions. However, MongoDB offers atomic operation on a single doc.

How are you able to obtain major key – international key relationships in MongoDB?

By default MongoDB doesn’t assist such major key – international key relationships. However, we are able to obtain this idea by embedding one doc inside one other. Foe e.g. an tackle doc could be embedded inside buyer doc.

Does MongoDB want a number of RAM?

No. MongoDB could be run even on a small quantity of RAM. MongoDB dynamically allocates and de-allocates RAM primarily based on the necessities of different processes.

Mongodb Interview Questions And Answers

Does MongoDB pushes the writes to disk instantly or lazily?

MongoDB pushes the information to disk lazily. It updates the instantly written to the journal however writing the information from journal to disk occurs lazily.

Explain the construction of ObjectID in MongoDB

ObjectID is a 12-byte BSON kind with:

  • Four bytes worth representing seconds
  • Three byte machine identifier
  • 2 byte course of id
  • Three byte counter

MongoDB makes use of BSON to characterize doc constructions. True or False?

True

If you take away a doc from database, does MongoDB take away it from disk?

Yes. Removing a doc from database removes it from disk too.

Mention the command to insert a doc in a database referred to as college and assortment referred to as individuals.
use college;
db.individuals.insert( title: “kadhir”, dept: “CSE” )

What are Indexes in MongoDB?

Indexes assist the environment friendly execution of queries in MongoDB. Without indexes, MongoDB should carry out a group scan, i.e. scan each doc in a group, to pick these paperwork that match the question assertion. If an applicable index exists for a question, MongoDB can use the index to restrict the variety of paperwork it should examine.

How many indexes does MongoDB create by default for a brand new assortment?

By default, MongoDB created the _id assortment for each assortment.

Can you create an index on an array discipline in MongoDB? If sure, what occurs on this case?
Yes. An array discipline could be listed in MongoDB. In this case, MongoDB would index every worth of the array.

What is a coated question in MongoDB?

A coated question is the one through which:

  • fields used within the question are a part of an index used within the question, and
  • the fields returned within the outcomes are in the identical index

Why is a coated question vital?

Since all of the fields are coated within the index itself, MongoDB can match the question situation in addition to return the end result fields utilizing the identical index with out wanting contained in the paperwork. Since indexes are saved in RAM or sequentially situated on disk, such entry is so much quicker.

Interview Questions On Mongodb

Does MongoDB present a facility to do textual content searches? How?

Yes. MongoDB helps creating textual content indexes to assist textual content search inside string content. This was a brand new function which might launched in model 2.6.

What occurs if an index doesn’t match into RAM?

If the indexes don’t match into RAM, MongoDB reads knowledge from disk which is comparatively very a lot slower than studying from RAM.

Mention the command to listing all of the indexes on a specific assortment.
db.assortment.getIndexes()

At what interval does MongoDB write updates to the disk?

By default configuration, MongoDB writes updates to the disk each 60 seconds. However, that is configurable with the commitIntervalMs and syncPeriodSecs choices.

How are you able to obtain transaction and locking in MongoDB?

To obtain ideas of transaction and locking in MongoDB, we are able to use the nesting of paperwork, additionally referred to as embedded paperwork. MongoDB helps atomic operations inside a single doc.

What is Aggregation in MongoDB?

Aggregations operations course of knowledge data and return computed outcomes. Aggregation operations group values from a number of paperwork collectively, and may carry out quite a lot of operations on the grouped knowledge to return a single end result. MongoDB offers 3 ways to carry out aggregation: the aggregation pipeline, the map-reduce operate, and single function aggregation strategies and instructions.

Mongodb Interview Questions For Experienced

What is Sharding in MongoDB? Explain

Sharding is a technique for storing knowledge throughout a number of machines. MongoDB makes use of sharding to assist deployments with very massive knowledge units and excessive throughput operations.

What is Replication in MongoDB? Explain

Replication is the method of synchronizing knowledge throughout a number of servers. Replication offers redundancy and will increase knowledge availability. With a number of copies of information on completely different database servers, replication protects a database from the lack of a single server. Replication additionally means that you can get well from {hardware} failure and repair interruptions.

What are Primary and Secondary Replica units?

Primary and grasp nodes are the nodes that may settle for writes. MongoDB’s replication is ‘single-master:’ just one node can settle for write operations at a time.

Secondary and slave nodes are read-only nodes that replicate from the first.

By default, MongoDB writes and reads knowledge from each major and secondary reproduction units. True or False.
False. MongoDB writes knowledge solely to the first reproduction set.

Why are MongoDB knowledge recordsdata massive in measurement?

MongoDB preallocates knowledge recordsdata to order area and keep away from file system fragmentation while you setup the server.

When ought to we embed one doc inside one other in MongoDB?

You ought to contemplate embedding paperwork for:

  • ‘comprises’ relationships between entities
  • One-to-many relationships
  • Performance causes

Why MongoDB is just not most well-liked over a 32-bit system?

When working a 32-bit construct of MongoDB, the entire storage measurement for the server, together with knowledge and indexes, is 2 gigabytes. For this cause, don’t deploy MongoDB to manufacturing on 32-bit machines.

If you are working a 64-bit construct of MongoDB, there’s nearly no restrict to storage measurement.

Mongodb Dba Interview Questions

What is a Storage Engine in MongoDB

A storage engine is the a part of a database that’s chargeable for managing how knowledge is saved on disk. For instance, one storage engine would possibly supply higher efficiency for read-heavy workloads, and one other would possibly assist a higher-throughput for write operations.

Which are the 2 storage engines utilized by MongoDB?

MongoDB makes use of MMAPv1 and WiredTiger.

What is the position of a profiler in MongoDB? Where does the writes all the information?
The database profiler collects tremendous grained knowledge about MongoDB write operations, cursors, database instructions on a working mongod occasion. You can allow profiling on a per-database or per-instance foundation.

The database profiler writes all the information it collects to the system.profile assortment, which is a capped assortment.

How does Journaling work in MongoDB?

When working with journaling, MongoDB shops and applies write operations in reminiscence and within the on-disk journal earlier than the adjustments are current within the knowledge recordsdata on disk. Writes to the journal are atomic, making certain the consistency of the on-disk journal recordsdata. With journaling enabled, MongoDB creates a journal subdirectory inside the listing outlined by dbPath, which is /knowledge/db by default.

Mention the command to test whether or not you might be on the grasp server or not.
db.isMaster()

Can you configure the cache measurement for MMAPv1? How?

No. MMAPv1 doesn’t enable configuring the cache measurement.

Can you configure the cache measurement for WiredTiger? How?

For the WiredTiger storage engine, you’ll be able to specify the utmost measurement of the cache that WiredTiger will use for all knowledge. This could be executed utilizing storage.wiredTiger.engineConfig.cacheSizeGB choice.

How does MongoDB present concurrency?

MongoDB makes use of reader-writer locks that enable concurrent readers shared entry to a useful resource, reminiscent of a database or assortment, however give unique entry to a single write operation.

How are you able to isolate your cursors from intervening with the write operations?

You can use the snapshot() technique on a cursor to isolate the operation for a really particular case. snapshot() traverses the index on the _id discipline and ensures that the question will return every doc not more than as soon as.

Mongodb Interview Questions And Answers For Experienced

Can one MongoDB operation lock multiple databases? If sure, how?

Yes. Operations like copyDatabase(), repairDatabase(), and so on. can lock greater than onne databases concerned.

How can concurrency have an effect on reproduction units major?

In replication, when MongoDB writes to a group on the first, MongoDB additionally writes to the first’s oplog, which is a particular assortment within the native database. Therefore, MongoDB should lock each the gathering’s database and the native database.

What is GridFS?

GridFS is a specification for storing and retrieving recordsdata that exceed the BSON-document measurement restrict of 16MB. Instead of storing a file in a single doc, GridFS divides a file into elements, or chunks, and shops every of these chunks as a separate doc.

Can you run a number of Javascript operations in a single mongod occasion?

Yes. The V8 JavaScript engine added in 2.Four permits a number of JavaScript operations to run on the similar time.

Which command can be utilized to supply numerous info on the question plans utilized by a MongoDB question?
The clarify() command can be utilized for this info. The potential modes are: ‘queryPlanner’, ‘executionStats’, and ‘allPlansExecution’.

Which are the completely different languages supported by MongoDB?

MonggoDB offers official driver assist for C, C++, C#, Java, Node.js, Perl, PHP, Python, Ruby, Scala, Go and Erlang.

You can use MongoDB with any of the above languages. There are another neighborhood supported drivers too however the above talked about ones are formally supplied by MongoDB.

What are the several types of NoSQL databases? Give some instance

NoSQL database could be categorised as Four fundamental varieties:

  • Key worth retailer NoSQL database
  • Document retailer NoSQL database
  • Column retailer NoSQL database
  • Graph base NoSQL databse

There are many NoSQL databases. MongoDB, Cassandra, CouchBD, Hypertable, Redis, Riak, Neo4j, HBASE, Couchbase, MemcacheDB, Voldemort, RevenDB and so on. are the examples of NoSQL databases.

Is MongoDB higher than different SQL databases? If sure then how?

MongoDB is healthier than different SQL databases as a result of it permits a extremely versatile and scalable doc construction.

For instance:

  • One knowledge doc in MongoDB can have 5 columns and the opposite one in the identical assortment can have ten columns.
  • MongoDB database are quicker than SQL databases as a result of environment friendly indexing and storage methods.

What kind of DBMS is MongoDB?

MongoDB is a doc oriented DBMS

What is the distinction between MongoDB and MySQL?

Although MongoDB and MySQL each are free and open supply databases, there’s a number of distinction between them within the time period of information illustration, relationship, transaction, querying knowledge, schema design and definition, efficiency pace, normalization and plenty of extra. To examine MySQL with MongoDB is sort of a comparability between Relational and Non-relational databases.

Mongodb Interview Questions For 2 Years Experienced

Why MongoDB is named greatest NoSQL database?

MongoDb is the most effective NoSQL database as a result of, it’s:

  • Document Oriented
  • Rich Query language
  • High Performance
  • Highly Available
  • Easily Scalable

Does MongoDB assist primary-key, foreign-key relationship?

No. By Default, MongoDB does not assist major key-foreign key relationship.

Can you obtain major key – international key relationships in MongoDB?

We can obtain major key-foreign key relationship by embedding one doc inside one other. For instance: An tackle doc could be embedded inside buyer doc.

Does MongoDB want a number of RAM?

No. There is not any want a number of RAM to run MongoDB. It could be run even on a small quantity of RAM as a result of it dynamically allocates and de-allocates RAM based on the requirement of the processes.

Explain the construction of ObjectID in MongoDB

ObjectID is a 12-byte BSON kind. These are:

  • Four bytes worth representing seconds
  • Three byte machine identifier
  • 2 byte course of id
  • Three byte counter

Is it true that MongoDB makes use of BSON to characterize doc construction?

Yes.

What are Indexes in MongoDB?

In MondoDB, Indexes are used to execute question effectively. Without indexes, MongoDB should carry out a group scan, i.e. scan each doc in a group, to pick these paperwork that match the question assertion. If an applicable index exists for a question, MongoDB can use the index to restrict the variety of paperwork it should examine.

By default, which index is created by MongoDB for each assortment?

By default, the_id assortment is created for each assortment by MongoDB.

What is a Namespace in MongoDB?

Namespace is a concatenation of the database title and the gathering title. Collection, through which MongoDB shops BSON objects.

Can journaling options be used to carry out secure sizzling backups?

Yes.

Why does Profiler use in MongoDB?

MongoDB makes use of a database profiler to carry out traits of every operation towards the database. You can use a profiler to search out queries and write operations

If you take away an object attribute, is it deleted from the database?

Yes, it’s. Remove the attribute after which re-save() the item.

In which language MongoDB is written?

MongoDB is written and carried out in C++.

Does MongoDB want so much area of Random Access Memory (RAM)?

No. MongoDB could be run on small free area of RAM.

Mongodb Query Interview Questions

What language you need to use with MongoDB?

MongoDB shopper drivers helps all the favored programming languages so there is no such thing as a difficulty of language, you need to use any language that you really want.

Does MongoDB database have tables for storing data?

No. Instead of tables, MongoDB makes use of “Collections” to retailer knowledge.

Do the MongoDB databases have schema?

Yes. MongoDB databases have dynamic schema. There is not any must outline the construction to create collections.

What is the tactic to configure the cache measurement in MongoDB?

MongoDB’s cache is just not configurable. Actually MongoDb makes use of all of the free areas on the system mechanically by means of reminiscence mapped recordsdata.

How to do Transaction/locking in MongoDB?

MongoDB does not use conventional locking or complicated transaction with Rollback. MongoDB is designed to be gentle weighted, quick and predictable to its efficiency. It retains transaction assist easy to boost efficiency.

Why 32 bit model of MongoDB will not be most well-liked ?

Because MongoDB makes use of reminiscence mapped recordsdata so while you run a 32-bit construct of MongoDB, the entire storage measurement of server is 2 GB. But while you run a 64-bit construct of MongoDB, this offers nearly limitless storage measurement. So 64-bit is most well-liked over 32-bit.

Is it potential to take away outdated recordsdata within the moveChunk listing?

Yes, These recordsdata could be deleted as soon as the operations are executed as a result of these recordsdata are made as backups throughout regular shard balancing operation. This is a guide cleanup course of and essential to unencumber area.

What should do if a shard is down or sluggish and also you do a question?

If a shard is down and also you even do question then your question will likely be returned with an error except you set a partial question choice. But if a shard is sluggish them Mongos will watch for them until response.

Explain the coated question in MongoDB

A question known as coated question if satisfies the next two circumstances:

  • The fields used within the question are a part of an index used within the question.
  • The fields returned within the outcomes are in the identical index.

What is the significance of coated question?

Covered question makes the execution of the question quicker as a result of indexes are saved in RAM or sequentially situated on disk. It makes the execution of the question quicker.

Covered question makes the fields are coated within the index itself, MongoDB can match the question situation in addition to return the end result fields utilizing the identical index with out wanting contained in the paperwork.

Mongodb Basic Interview Questions

What is sharding in MongoDB?

In MongoDB, Sharding is a process of storing knowledge data throughout a number of machines. It is a MongoDB method to fulfill the calls for of information progress. It creates horizontal partition of information in a database or search engine. Each partition is referred as shard or database shard.

What is reproduction set in MongoDB?

A reproduction could be specified as a gaggle of mongo cases that host the identical knowledge set. In a reproduction set, one node is major, and one other is secondary. All knowledge is replicated from major to secondary nodes.

What is major and secondary reproduction set in MongoDB?

In MongoDB, major nodes are the node that may settle for write. These are often known as grasp nodes. The replication in MongoDB is single grasp so, just one node can settle for write operations at a time.

Secondary nodes are often called slave nodes. These are learn solely nodes that replicate from the first.

By default, which reproduction units are used to put in writing knowledge?

By default, MongoDB writes knowledge solely to the first reproduction set.

What is CRUD in MongoDB?

MongoDB helps following CRUD operations:

  • Create
  • Read
  • Update
  • Delete

In which format MongoDB represents doc construction?

MongoDB makes use of BSON to characterize doc constructions.

What will occur while you take away a doc from database in MongoDB? Does MongoDB take away it from disk?

Yes. If you take away a doc from database, MongoDB will take away it from disk too.

Mongodb Interview Questions For Java Developers

Why are MongoDB knowledge recordsdata massive in measurement?

MongoDB does not observe file system fragmentation and pre allocates knowledge recordsdata to order area whereas organising the server. That’s why MongoDB knowledge recordsdata are massive in measurement.

What is a storage engine in MongoDB?

A storage engine is the a part of a database that’s used to handle how knowledge is saved on disk.

For instance: one storage engine would possibly supply higher efficiency for read-heavy workloads, and one other would possibly assist a higher-throughput for write operations.

Which are the storage engines utilized by MongoDB?

MMAPv1 and WiredTiger are two storage engine utilized by MongoDB.

What is the utilization of profiler in MongoDB?

A database profiler is used to gather knowledge about MongoDB write operations, cursors, database instructions on a working mongod occasion. You can allow profiling on a per-database or per-instance foundation.

The database profiler writes all the information it collects to the system. profile assortment, which is a capped assortment.

Is it potential to configure the cache measurement for MMAPv1 in MongoDB?

No. it’s not potential to configure the cache measurement for MMAPv1 as a result of MMAPv1 doesn’t enable configuring the cache measurement.

Interview Questions Mongodb

How to configure the cache measurement for WiredTiger in MongoDB?

For the WiredTiger storage engine, you’ll be able to specify the utmost measurement of the cache that WiredTiger will use for all knowledge. This could be executed utilizing storage.wiredTiger.engineConfig.cacheSizeGB choice.

How does MongoDB present concurrency?

MongoDB makes use of reader-writer locks for concurrency. Reader-writer locks enable concurrent readers shared entry to a useful resource, reminiscent of a database or assortment, however give unique entry to a single write operation.

What is the distinction between MongoDB and Redis database?

Difference between MongoDB and Redis:

  • Redis is quicker than MongoDB.
  • Redis has a key-value storage whereas MongoDB has a doc kind storage.
  • Redis is tough to code however MongoDB is simple.

What is the distinction between MongoDB and CouchDB?

Difference between MongoDB and CouchDB:

  • MongoDB is quicker than CouchDB whereas CouchDB is safer than MongoDB.
  • Triggers will not be obtainable in MongoDB whereas triggers can be found in CouchDB.
  • MongoDB serializes JSON knowledge to BSON whereas CouchDB does not retailer knowledge in JSON format.

What is the distinction between MongoDB and Cassandra?

Difference between MongoDB and Cassandra:

  • MongoDB is cross-platform document-oriented database system whereas Cassandra is excessive efficiency distributed database system.
  • MongoDB is written in C++ whereas Cassandra is written in Java.
  • MongoDB is simple to manage within the case of failure whereas Cassandra offers excessive availability with no single level of failure.

Is there any must create database command in MongoDB?

You needn’t create a database manually in MongoDB as a result of it creates automaically while you save the worth into the outlined assortment at first time.


Spread the love