MongoDB Interview Questions


Dear readers, these MongoDB Interview Questions have been designed specially to get you acquainted with the nature of questions you may encounter during your interview for the subject of MongoDB. As per my experience good interviewers hardly plan to ask any particular question during your interview, normally questions start with some basic concept of the subject and later they continue based on further discussion and what you answer:


Types of NoSQL databases:

  • Document Oriented
  • Key Value
  • Graph
  • Column Oriented

MongoDB is a document oriented database. It stores data in the form of BSON structure based documents. These documents are stored in a collection.

  • Flexible data model in form of documents
  • Agile and highly scalable database
  • Faster than traditional databases
  • Expressive query language

A Namespace is the concatenation of the database name and collection name. For e.g. school.students with school as the database and students as the collection

Currently, MonggoDB provides official driver support for C, C++, C#, Java, Node.js, Perl, PHP, Python, Ruby, Scala, Go and Erlang. MongoDB can easily be used with any of these languages. There are some other community supported drivers too but the above mentioned ones are officially provided by MongoDB.

SQL databases store data in form of tables, rows, columns and records. This data is stored in a pre-defined data model which is not very much flexible for today's real-world highly growing applications. MongoDB in contrast uses a flexible structure which can be easily modified and extended.

MongoDB allows a highly flexible and scalable document structure. For e.g. one data document in MongoDB can have five columns and the other one in the same collection can have ten columns. Also, MongoDB database are faster as compared to SQL databases due to efficient indexing and storage techniques.

Although both of these databases are document oriented, MongoDB is a better choice for applications which need dynamic queries and good performance on a very big database. On the other side, CouchDB is better used for applications with occasionally changing queries and pre-defined queries.

No. MongoDB does not support such relationships.

No. MongoDB does not support default multi-document ACID transactions. However, MongoDB provides atomic operation on a single document.

By default MongoDB does not support such primary key - foreign key relationships. However, we can achieve this concept by embedding one document inside another. Foe e.g. an address document can be embedded inside customer document.

No. MongoDB can be run even on a small amount of RAM. MongoDB dynamically allocates and de-allocates RAM based on the requirements of other processes.

MongoDB pushes the data to disk lazily. It updates the immediately written to the journal but writing the data from journal to disk happens lazily.

ObjectID is a 12-byte BSON type with:

  • 4 bytes value representing seconds
  • 3 byte machine identifier
  • 2 byte process id
  • 3 byte counter


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

use school;
db.persons.insert( { name: "kadhir", dept: "CSE" } )


By default, MongoDB created the _id collection for every collection.

Yes. An array field can be indexed in MongoDB. In this case, MongoDB would index each value of the array.

A covered query is the one in which:

  • fields used in the query are part of an index used in the query, and
  • the fields returned in the results are in the same index










Primary and master nodes are the nodes that can accept writes. MongoDB's replication is 'single-master:' only one node can accept write operations at a time.

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

False. MongoDB writes data only to the primary replica set.

MongoDB preallocates data files to reserve space and avoid file system fragmentation when you setup the server.

You should consider embedding documents for:

  • 'contains' relationships between entities
  • One-to-many relationships
  • Performance reasons


If you're running a 64-bit build of MongoDB, there's virtually no limit to storage size.

A storage engine is the part of a database that is responsible for managing how data is stored on disk. For example, one storage engine might offer better performance for read-heavy workloads, and another might support a higher-throughput for write operations.

MongoDB uses MMAPv1 and WiredTiger.

The database profiler collects fine grained data about MongoDB write operations, cursors, database commands on a running mongod instance. You can enable profiling on a per-database or per-instance basis.

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

When running with journaling, MongoDB stores and applies write operations in memory and in the on-disk journal before the changes are present in the data files on disk. Writes to the journal are atomic, ensuring the consistency of the on-disk journal files. With journaling enabled, MongoDB creates a journal subdirectory within the directory defined by dbPath, which is /data/db by default.


No. MMAPv1 does not allow configuring the cache size.

For the WiredTiger storage engine, you can specify the maximum size of the cache that WiredTiger will use for all data. This can be done using storage.wiredTiger.engineConfig.cacheSizeGB option.

MongoDB uses reader-writer locks that allow concurrent readers shared access to a resource, such as a database or collection, but give exclusive access to a single write operation.

You can use the snapshot() method on a cursor to isolate the operation for a very specific case. snapshot() traverses the index on the _id field and guarantees that the query will return each document no more than once.

Yes. Operations like copyDatabase(), repairDatabase(), etc. can lock more than onne databases involved.

In replication, when MongoDB writes to a collection on the primary, MongoDB also writes to the primary's oplog, which is a special collection in the local database. Therefore, MongoDB must lock both the collection's database and the local database.


Yes. The V8 JavaScript engine added in 2.4 allows multiple JavaScript operations to run at the same time.

The explain() command can be used for this information. The possible modes are: 'queryPlanner', 'executionStats', and 'allPlansExecution'.

What is Next ?




E-Books Store