Mongo-DB Interview Questions and Answers

Q1 :  What are alternatives to MongoDB?
A : Cassandra, CouchDB, Redis, Riak, HBase are a few good alternatives.

Q2 : What is Objecld composed of?
A : Objectld is composed of

  • Timestamp
  • Client machine ID
  • Client process ID
  • 3 byte incremented counter

Q3 : What makes MongoDB the best?
A : MongoDB is considered to be best NoSQL database because of :Document-oriented (DO)
High performance (HP)
High availability (HA)
Easy scalability
Rich query language

Q4 : What is a replica set?
A : A replica set is a group of mongo instances that host the same data set. In replica set, one node is primary, and another is secondary. From primary to the secondary node all data replicates.
Q5 : What is MongoDB?
A : Mongo-DB is a document database which provides high performance, high availability and easy scalability.
Q6 : How replication works in MongoDB?
A : Across multiple servers, the process of synchronizing data is known as replication. It provides redundancy and increases data availability with multiple copies of data on different database server. Replication helps in protecting the database from the loss of a single server.
Q7 : What is the role of profiler in MongoDB?
A : MongoDB database profiler shows the performance characteristics of each operation against the database. You can find queries using the profiler that are slower than they should be.

Q8 : How to do transactions/locking in MongoDB?
A : MongoDB does not use conventional locking with reduction, as it is planned to be light, high-speed and knowable in its presentation. It can be considered as parallel to the MySQL MyISAM auto entrust sculpt. With simplest business sustain, performance is enhanced, particularly in a structure with numerous servers.

Q9 : When do we use Namespace in MongoDB?
A : During the sequencing of the names of the database and collection name Namespace is used.

Q10 : Why is MongoDB not chosen for a 32-bit system?
A : Mongo DB is not considered as a 32-bit system because for running the 32-bit MongoDB, with the server, information and indexes require 2 GB. So only it is not used in 32-bit devices.

Q11 : What is CRUD?
A : MongoDB provides CRUD operations that are create, Read, Update, Delete.

Q12 : What are the differences between MongoDB and MySQL?
A : The various differences between MongoDB and MySQL are listed below:

  • In terms of data representation– in MySQL, we represent data in the form of tables and rows. Whereas, in MongoDB data is represented as collections of JSON documents.
  • Querying– in SQL, we put together a string in the query language which is then parsed by the database system. Whereas, in MongoDB, object querying is used.
  • Relationships– in MySQL, the relational database is only the Join operation which allows us to perform queries across multiple tables. Whereas MongoDB does not support join operation but can support multi-dimensional data types such as arrays, etc. in this, embedding is a process in which we place one document inside the other.
  • Transactions– MySQL supports atomic transactions which are the ability to contain multiple operations within a transaction. Whereas, MongoDB does not support transactions.
  • Schema definition– in MySQL, you need to define your tables and columns before storing anything. Whereas, in MongoDB, you don’t need to define a schema.

Q13 : What is the syntax to create a collection and to drop a collection in MongoDB?
A : 

  • Syntax to create collection in MongoDB is db.createCollection(name,options)
  • Syntax to drop collection in MongoDB is db.collection.drop()

Q14 : How can you see the connection used by Mongos?
A : To see the connection used by Mongos use db_adminCommand (“connPoolStats”);

Q15 : What is Aggregation in MongoDB?
A : Aggregations are operations that process data records and return computed results.

Q16 : What is the use of GridFS in MongoDB?
A : GridFS is used for storing and retrieving the large files like audio, Images, Video files.

Q17 : How you can inspect the source code of a function?
A : To inspect a source code of a function, without any parentheses, the function must be invoked.
Q18 : What are indexes in MongoDB?
A : Indexes are special structures in MongoDB, which stores a small portion of the data set in an easy to traverse form. Ordered by the value of the field specified in the index, the index stores the value of a specific field or set of fields.
Q19 : Explain can you move old files in the moveChunk directory?
A : Yes, it is possible to move old files in the moveChunk directory, during normal shard balancing operations these files are made as backups and can be deleted once the operations are done.

Q20 : What is the use of journaling?
A : Journaling is used to safe backups in MongoDB

Q21 : Which type of data MongoDB store?
A : MongoDB stores data in the form of documents, which are JSON-like field and value pairs.

Q22 : What is embedded documents?
A : Embedded documents capture relationships between data by storing related data in a single document structure.

Q23 : Which method is used to create an index?
A :
Create Index() method is used to create an index.

Q24 : Define MongoDB projection.
A : Projection is used to select only necessary data. It did not select whole data of a document.

Q25 : If you remove an object attribute, is it deleted from the database?
A : Yes, it is deleted. So better eliminate the attribute and then save the object again.