Mongo DB Q&A

[vc_row][vc_column css_animation=”fadeInLeft”][vc_column_text css=”.vc_custom_1562139087314{background-color: #1e73be !important;}”]

Mongo DB Interview Questions & Answers

[/vc_column_text][/vc_column][/vc_row][vc_row css_animation=”fadeInRight”][vc_column css_animation=”fadeInLeft” width=”1/2″][vc_tta_accordion color=”peacoc” active_section=”1″][vc_tta_section title=”Compare MongoDB and Cassandra?” tab_id=”1562139105178-da670454-7902″][vc_column_text]

Criteria MongoDB Cassandra
Data Model Document Big Table like
Database scalability Read Write
Querying of data Multi-indexed Using Key or Scan

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What makes MongoDB the best?” tab_id=”1562139105194-8387f937-6b7f”][vc_column_text]MongoDB is considered to be best NoSQL database because of :Document-oriented (DO)
High performance (HP)
High availability (HA)
Easy scalability
Rich query language[/vc_column_text][/vc_tta_section][vc_tta_section title=”How to do transactions/locking in MongoDB?” tab_id=”1562139147327-1a528eae-1b17″][vc_column_text]

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.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”When and to what extent does Data get extended to Multi-slice?” tab_id=”1562139147867-ab7f8de4-0517″][vc_column_text]The MongoDB scrap stands on a collection. So an album of all substances is kept in a lump or mass. Only when there is an additional time slot, there will be more than a few slice data achievement choices, but when there is more than 1 lump, data gets extended to a lot of slices and it can be extended to 64 MB.[/vc_column_text][/vc_tta_section][vc_tta_section title=”Judge against MongoDB with Couchbase and CouchbaseDB?” tab_id=”1562139148435-f3ce600e-cce8″][vc_column_text]

Although Mongo DB with Couchbase and Couchbase DB are common in many ways, but still they are different in the case of necessities for execution of the model, crossing points, storage, duplications, etc.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”When do we use Namespace in MongoDB?” tab_id=”1562139148983-a24b9517-beaf”][vc_column_text]

During sequencing of the names of the database and collection name Namespace is used.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”If you remove an object attribute, is it deleted from the database?” tab_id=”1562139150159-fd5b397f-df31″][vc_column_text]

Yes, it is deleted. So better eliminate the attribute and then save the object again.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”How can we move the old file in the moveChunk directory?” tab_id=”1562139150663-c7d081f8-4c88″][vc_column_text]

Once the functions are done, the old files are converted to backup files and moved to the moveChunk directory at the time of balancing the slices.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Explain the situation when an index does not fit into RAM?” tab_id=”1562139151262-303a2eee-f93e”][vc_column_text]

When an index is too huge to fit into RAM, then MongoDB reads the index, which is faster than reading RAM because the indexes easily fit into RAM if the server has got RAM for indexes along with the remaining set.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”How does MongoDB provide consistency?” tab_id=”1562139151826-daa2d80e-d9e3″][vc_column_text]

MongoDB uses the reader-writer locks, allowing simultaneous readers to access any supply like a database or any collection. But always offers private access to singles writes.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Why is MongoDB not chosen for a 32-bit system?” tab_id=”1562139152459-89a0ddac-3729″][vc_column_text]

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.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”How does Journaling work in MongoDB?” tab_id=”1562139153083-5a4d1056-925c”][vc_column_text]

Write operations are saved in the memory while journaling is going on. The on-disk journal files are really dependable for the reason that the journal writes are habitual. Inside dbPath, a journal subdirectory is designed by MongoDB.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”How can you isolate our cursors from intervening with the write operations?” tab_id=”1562139154296-b8a475cc-a7f9″][vc_column_text]

Snapshot () method is used to isolate cursors from intervening with writes. This method negotiates the index and makes sure that each query comes to any article only once.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Define MongoDB.” tab_id=”1562139154855-036b643c-d881″][vc_column_text]

It is document oriented database which is used to high availability, easy scalability and high performance. It supports the dynamic schema design.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Explain replica set.” tab_id=”1562139155485-241a4e48-2a71″][vc_column_text]

It is a group of mongo instances that maintain same data set. Replica sets provide redundancy and high availability, and are the basis for all production deployments.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What are the key features of mongodb?” tab_id=”1562139156009-a77b339d-bbaa”][vc_column_text]

There are 3 main features of mongodb that are automatic scaling, High performance and high availability.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is CRUD?” tab_id=”1562139157200-950dd274-0da6″][vc_column_text]Mongodb provides CRUD operations that are create, Read, Update, Delete.[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is sharding?” tab_id=”1562139157747-6c6d0b2a-263a”][vc_column_text]

Sharding means to store the data on the multiple machines.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is Aggregation in MongoDB?” tab_id=”1562139158320-7986041c-5bbf”][vc_column_text]

Aggregations are operations that process data records and return computed results.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Define the namespace in mongodb?” tab_id=”1562139158857-b3df27ed-6cb1″][vc_column_text]

It is the concatenation of collection name and database.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Which syntax is used to create collection in mongodb?” tab_id=”1562139159491-db1ff5ae-1077″][vc_column_text]

db.createCollection(name,options) is used to create collection in mongodb.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Which syntax is used to drop collection in mongodb?” tab_id=”1562139160714-295fd9f5-55c1″][vc_column_text]

db.collection.drop() is used to drop collection in mongodb.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Explain Replication.” tab_id=”1562139161265-240b4f65-df75″][vc_column_text]

Replication is the process of synchronizing data across multiple servers.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is the use of Index in mongodb?” tab_id=”1562139161808-d18bb21e-0e3d”][vc_column_text]

Indexes provide high performance read operations for frequently used queries.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Which command is used for inserting a document?” tab_id=”1562139162460-2a6798db-c3aa”][vc_column_text]

database.collection.insert (document) is used for inserting a document.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is use of GridFS in mongodb?” tab_id=”1562139162994-54e4bc7a-e691″][vc_column_text]

GridFS is used for storing and retrieving the large files like audio, Images, Video files.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is the use journaling?” tab_id=”1562139163567-3388813c-d69c”][vc_column_text]

Journaling is used to safe backups in mongodb.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Which command is used to see the connection?” tab_id=”1562139164226-f9968699-0c9e”][vc_column_text]

db_adminCommand (“connPoolStats”); is used to see the connection.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Define primary replica sets?” tab_id=”1562139165289-ac50cef7-a759″][vc_column_text]

The primary replica set accepts all write operations from clients.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Define secondary replica sets.” tab_id=”1562139165996-ebbd0f92-f6ec”][vc_column_text]

The secondaries (page 565) replicate the primary’s oplog and apply the operations to their data sets such that the secondaries’ data sets reflect the primary’s data set.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is the use of profiler?” tab_id=”1562139166560-4159b689-99a1″][vc_column_text]

Profiler is used to show the performance characteristics of every operation against the database.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Which type of data mongodb store?” tab_id=”1562139167234-a240c63d-3922″][vc_column_text]

MongoDB stores data in the form of documents, which are JSON-like field and value pairs.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is purpose of replication?” tab_id=”1562139167818-ce812fb7-50f1″][vc_column_text]

Replication provides redundancy and increases data availability.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”what is embedded documents?” tab_id=”1562139169107-69128248-76d1″][vc_column_text]

Embedded documents capture relationships between data by storing related data in a single document structure.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Define application level encryption.” tab_id=”1562139169761-0a1095d5-c8a8″][vc_column_text]Application Level Encryption provides encryption on a per-field or per-document basis within the application layer.[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is storage encryption?” tab_id=”1562139170586-065e74f2-cd71″][vc_column_text]

Storage Encryption encrypts all MongoDB data on the storage or operating system to ensure that only authorized processes can access protected data.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Which method is used to create an index?” tab_id=”1562139171667-75184383-cbfd”][vc_column_text]

CreateIndex() method is used to create an index.

[/vc_column_text][/vc_tta_section][/vc_tta_accordion][/vc_column][vc_column width=”1/2″][vc_tta_accordion color=”peacoc” active_section=”1″][vc_tta_section title=”What is replica set oplog?” tab_id=”1562139188697-1a4e405b-8a1e”][vc_column_text]

The oplog records all operations that modify the data in the replica set.

[/vc_column_text][/vc_tta_section][vc_tta_section title=” What is vertical scaling?” tab_id=”1562139188713-ca5f913b-23ed”][vc_column_text]

Vertical scaling adds more CPU and storage resources to increase capacity.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Define horizontal scaling.” tab_id=”1562139202875-05ee2cb2-17f0″][vc_column_text]

It divides the data set and distributes the data over multiple servers, or shards.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”SectionWhat are the components of shared cluster?” tab_id=”1562139206939-27c638bb-617d”][vc_column_text]

Sharded cluster has the following components: shards, query routers and config servers.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Which command is use to create database?” tab_id=”1562139207832-fe5104fb-e840″][vc_column_text]

DATABASE_NAME command is used to create database.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Which command is use to drop database?” tab_id=”1562139208542-3aae99ef-4657″][vc_column_text]

db.dropDatabse() command is used to drop the database.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is the use of pretty() method?” tab_id=”1562139209082-7b3b48a9-7cfd”][vc_column_text]

Pretty() method is used to show the results in a formatted way.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Which method is used to remove the document form the collection?” tab_id=”1562139210258-b1085618-4977″][vc_column_text]

Remove() method is used to remove the document form the collection.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Define Mongodb projection.” tab_id=”1562139210890-979cad59-c04e”][vc_column_text]

Projection is used to select only necessary data.It did not select whole data of a document.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is the use of limit() method?” tab_id=”1562139211546-3d258502-85db”][vc_column_text]

Limit() method is used to limit the records in database.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is the syntax of limit() method?” tab_id=”1562139212134-d16f7148-8b84″][vc_column_text]

>db.COLLECTION_NAME.find().limit(NUMBER) syntax is used.

[/vc_column_text][/vc_tta_section][vc_tta_section title=” What is the syntax of sort() method?” tab_id=”1562139212712-414d7f04-f546″][vc_column_text]

>db.COLLECTION_NAME.find().sort({KEY:1}) syntax is used for sorting the documents.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Which command is used to create the backup of database?” tab_id=”1562139213266-eb92e5e9-f099″][vc_column_text]

Mongodump command is used to create the backup of database.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is collection in monodb?” tab_id=”1562139214506-71d55be0-6845″][vc_column_text]

In monogodb collection is a group of mongodb documents.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is the use of db command?” tab_id=”1562139215258-b352f00f-605e”][vc_column_text]

Db command gives the name of currently selected database.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Which method is used to update the documents into a collection?” tab_id=”1562139215817-485356ca-8cc8″][vc_column_text]

Update() and save() methods are used to update the documents into a collection.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is the syntax of skip() method?” tab_id=”1562139217081-7ff88984-365c”][vc_column_text]

The syntax of skip methopd is >db.COLLECTION_NAME.find().limit(NUMBER).skip(NUMBER).

[/vc_column_text][/vc_tta_section][vc_tta_section title=” Which command is used to restore the backup?” tab_id=”1562139217835-41d9227b-6d68″][vc_column_text]

Mongorestore command is used to restore the backup.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is the use of Dot notation in mogodb?” tab_id=”1562139218452-d4f86f10-b248″][vc_column_text]

MongoDB uses the dot notation to access the elements of an array and to access the fields of an embedded document.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Define auditing.” tab_id=”1562139218989-24bfbcec-be4d”][vc_column_text]

Auditing provides administrators with the ability to verify that the implemented security policies are controlling activity in the system.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Define Aggregation Pipeline.” tab_id=”1562139219627-21ec4d28-5ed7″][vc_column_text]

It is a framework for performing aggregation tasks.T he pipeline is used to transform the documents into aggregated results.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Define Map reduce.” tab_id=”1562139220213-708535fd-0ffb”][vc_column_text]

Map-reduce is a generic multi-phase data aggregation modality which is used for processing quantities of data.

[/vc_column_text][/vc_tta_section][vc_tta_section title=” What is splitting in mongodb?” tab_id=”1562139220773-ca6e03ff-eba7″][vc_column_text]

It is a background process that is used to keep chunks from growing too large.

[/vc_column_text][/vc_tta_section][vc_tta_section title=” Which language is used to wite mongodb?” tab_id=”1562139221371-e4b24e2a-9c38″][vc_column_text]

C++ language is used for writing and implementing mongodb.

[/vc_column_text][/vc_tta_section][vc_tta_section title=” In which format mongodb stores the data?” tab_id=”1562139222786-60ee3920-26ed”][vc_column_text]

Mongodb uses collection to store the data rather than in table.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is the use of save() method?” tab_id=”1562139223426-5895a62e-2c20″][vc_column_text]

Save() method is used to replace the existing document to the new document.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is MongoDB?” tab_id=”1562139224027-5194dd75-ef8e”][vc_column_text]MongoDB (from humongous) is a cross-platform document-oriented database. Classified as a NoSQL database, MongoDB eschews the traditional table-based relational database structure in favor of JSON-like documents with dynamic schemas (MongoDB calls the format BSON), making the integration of data in certain types of applications easier and faster. Released under a combination of the GNU Affero General Public License and the Apache License, MongoDB is free and open-source software.

First developed by the software company 10gen (now MongoDB Inc.) in October 2007 as a component of a planned platform as a service product, the company shifted to an open source development model in 2009, with 10gen offering commercial support and other services. Since then, MongoDB has been adopted as backend software by a number of major websites and services, including Craigslist, eBay, Foursquare, SourceForge, Viacom, and the New York Times, among others. MongoDB is the most popular NoSQL database system[/vc_column_text][/vc_tta_section][vc_tta_section title=” What is the use of MongoDB?” tab_id=”1562139224568-2a39756c-e68d”][vc_column_text]MongoDB is relational database management system (RDBMS) replacement for web applications. So when you have something which is close to RDBMS, MongoDB could be of good use. It gives you that additional partition tolerance which RDMBS doesn’t give but it has problems with availability. But if you want more scalability, MongoDB would be your choice.

It’s suitable for real-time analytics and high speed logging. It’s highly scalable as well. Craigslist uses MongoDB for archived posts.[/vc_column_text][/vc_tta_section][vc_tta_section title=”What do you understand by NoSQL databases? Is MongoDB a NoSQL database? Explain.” tab_id=”1562139225156-45221cad-edc2″][vc_column_text]At the present time, the internet is loaded with big data, big users, big complexity etc. and also becoming more complex day by day. NoSQL is answer of all these problems; it is not a traditional database management system, not even a relational database management system (RDBMS). NoSQL stands for “Not Only SQL”. NoSQL is a type of database that can handle and sort all type of unstructured, messy and complicated data. It is just a new way to think about the database.Yes. MongoDB is a NoSQL database.[/vc_column_text][/vc_tta_section][vc_tta_section title=”What type of DBMS is MongoDB?” tab_id=”1562139225732-9dea9c45-c9c6″][vc_column_text]

MongoDB is a document oriented DBMS.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is the difference between MongoDB and MySQL?” tab_id=”1562139226278-ee2caf25-cf29″][vc_column_text]

Although MongoDB and MySQL both are free and open source databases, there is a lot of difference between them in the term of data representation, relationship, transaction, querying data, schema design and definition, performance speed, normalization and many more. To compare MySQL with MongoDB is like a comparison between Relational and Non-relational databases.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is the use of MongoDB?” tab_id=”1562139226902-13ff8750-1552″][vc_column_text]

  • MongoDB is typically used as the primary data store for operational applications with real-time requirements (i.e., low-latency, high availability). MongoDB is generally a good fit for 60%-80% of the applications you may be building today. MongoDB is easy to operate and scale in ways that are hard if not impossible with relational databases.
  • MongoDB excels in many use cases where relational databases aren’t a good fit, like applications with unstructured, semi-structured and polymorphic data, as well as applications with large scalability requirements or multi-data center deployments.
  • MongoDB may not be a good fit for some applications. For example, applications that require complex transactions (e.g., a double-entry bookkeeping system) and scan-oriented applications that access large subsets of the data most of the time may not be a good fit for MongoDB. MongoDB is not a drop-in replacement for legacy applications built around the relational data model and SQL.
  • Some common use cases include mobile apps, product catalogs, real-time personalization, content management and applications delivering a single view across multiple systems

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What kind of database is MongoDB?” tab_id=”1562139228177-398a34ff-d431″][vc_column_text]MongoDB is a document-oriented DBMS. Think of MySQL but with JSON-like objects comprising the data model, rather than RDBMS tables. Significantly, MongoDB supports neither joins nor transactions. However, it features secondary indexes, an expressive query language, atomic writes on a per-document level, and fully-consistent reads.
Operationally, MongoDB features master-slave replication with automated failover and built-in horizontal scaling via automated range-based partitioning.[/vc_column_text][/vc_tta_section][vc_tta_section title=”What language is MongoDB written in?” tab_id=”1562139228811-1a87c99c-2b7d”][vc_column_text]MongoDB is implemented in C++. Drivers and client libraries are typically written in their respective languages, although some drivers use C extensions for better performance.[/vc_column_text][/vc_tta_section][vc_tta_section title=”What are the limitations of 32-bit versions of MongoDB?” tab_id=”1562139229453-d5dd2b8d-eef7″][vc_column_text]MongoDB uses memory-mapped files. When running a 32-bit build of MongoDB, the total storage size for the server, including data and indexes, is 2 gigabytes. For this reason, do not deploy MongoDB to production on 32-bit machines.
If you’re running a 64-bit build of MongoDB, there’s virtually no limit to storage size. For production deployments, 64-bit builds and operating systems are strongly recommended.[/vc_column_text][/vc_tta_section][vc_tta_section title=”While creating Schema in MongoDB what are the points need to be taken in consideration?” tab_id=”1562139230213-e182df15-beb1″][vc_column_text]Points need to be taken in consideration are:

  • Design your schema according to user requirements
  • Combine objects into one document if you use them together. Otherwise, separate them
  •  Do joins while write, and not when it is on read
  • For most frequent use cases optimize your schema
  • Do complex aggregation in the schemaThis blog will help you get a better understanding of Difference Between Cassandra and MongoDB!


WhatsApp us