Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

What are some utilities for backup and restore in MongoDB?

Answer»

The mongo shell does not include FUNCTIONS for exporting, importing, backup, or RESTORE. HOWEVER, MongoDB has created methods for accomplishing this, so that no scripting work or complex GUIs are needed. For this, several utility scripts are provided that can be used to get data in or out of the database in BULK. These utility scripts are:

  • mongoimport
  • mongoexport
  • mongodump
  • mongorestore
2.

Explain the Replication Architecture in MongoDB.

Answer»

The following diagram depicts the ARCHITECTURE diagram of a simple replica set cluster with only three server nodes – one PRIMARY node and two SECONDARY nodes:

  • In the preceding model, the PRIMARY database is the only active replica set member that receives write operations from database clients. The PRIMARY database saves data changes in the Oplog. Changes saved in the Oplog are sequential—that is, saved in the order that they are received and executed. 
  • The SECONDARY database is querying the PRIMARY database for new changes in the Oplog. If there are any changes, then Oplog entries are copied from PRIMARY to SECONDARY as soon as they are created on the PRIMARY node.
  • Then, the SECONDARY database applies changes from the Oplog to its own datafiles. Oplog entries are applied in the same order they were inserted in the log. As a result, datafiles on SECONDARY are kept in sync with changes on PRIMARY. 
  • Usually, SECONDARY databases copy data changes DIRECTLY from PRIMARY. Sometimes a SECONDARY database can replicate data from another SECONDARY. This type of replication is CALLED Chained Replication because it is a two-step replication process. Chained replication is useful in certain replication topologies, and it is enabled by default in MongoDB.
3.

What is a Replica Set in MongoDB?

Answer»

To keep identical copies of your data on multiple servers, we use REPLICATION. It is RECOMMENDED for all production deployments. Use replication to keep your application running and your data safe, even if something happens to one or more of your servers.

Such replication can be created by a REPLICA set with MongoDB. A replica set is a GROUP of servers with one primary, the server taking writes, and multiple secondaries, servers that keep copies of the primary’s data. If the primary crashes, the secondaries can elect a new primary from amongst themselves.

4.

Explain the concept of pipeline in the MongoDB aggregation framework.

Answer»

An individual stage of an AGGREGATION pipeline is a data processing UNIT. It TAKES in a stream of input DOCUMENTS one at a time, processes each document one at a time, and produces an output stream of documents one at a time (see figure below).

5.

What is the Aggregation Framework in MongoDB?

Answer»
  • The aggregation framework is a SET of ANALYTICS tools within MongoDB that allow you to do analytics on documents in one or more collections.
  • The aggregation framework is based on the concept of a pipeline. With an aggregation pipeline, we take input from a MongoDB collection and pass the documents from that collection through one or more stages, each of which performs a different operation on its INPUTS (See FIGURE below). Each STAGE takes as input whatever the stage before it produced as output. The inputs and outputs for all stages are documents—a stream of documents.
6.

What are MongoDB Charts?

Answer»

MongoDB CHARTS is a new, integrated tool in MongoDB for DATA visualization.

MongoDB Charts offers the best way to create visualizations using data from a MongoDB DATABASE.
It allows users to perform quick data representation from a database without writing code in a programming language such as Java or Python.

The TWO different implementations of MongoDB Charts are:

  • MongoDB Charts PaaS (Platform as a Service)
  • MongoDB Charts SERVER
7.

What do you mean by Transactions?

Answer»

A transaction is a logical unit of processing in a database that includes one or more database operations, which can be read or write operations. Transactions PROVIDE a useful feature in MongoDB to ensure consistency.

MongoDB provides two APIs to use transactions. 

  • Core API: It is a SIMILAR syntax to RELATIONAL databases (e.g., start_transaction and commit_transaction)
  • Call-back API: This is the recommended approach to using transactions. It starts a transaction, executes the specified operations, and commits (or aborts on the error). It ALSO automatically incorporates error handling logic for "TransientTransactionError" and"UnknownTransactionCommitResult".