Blog about Programming Languages & Coding

Blog about Programming Languages & Coding
Contents for Computer Science, IT, B.Sc. CS & IT, M.Sc. CS & IT, MCA, BE CS & IT, ME CS & IT , Interview Questions, Books and Online Course Recommendations from Udemy, Coursera, etc

MongoDB Interview Questions

 MongoDB MCQs & Interview Questions


MongoDB Interview Questions

1) What is use of capped collection in MongoDB?

2) What are Primary and Secondary Replica sets?

3) What is splitting in mongodb?

4) What do you know about MongoDB?

5) Explain what is MongoDB?

6) List some important features of MongoDB?

7) What is namespace in MongoDB?

8) What is BSON in MongoDB?

9) What type of DBMS is MongoDB?

10) What is the document structure of MongoDB?

11) What is replica set in MongoDB?

12) What is profiler in MongoDB?

13) Write the syntax for creating and droping a collection in MongoDB?

14) What is the size limit of a document?

15) What is _id Field in MongoDB?

16) Explain what is ObjectId in MongoDB?

17) Write syntax to create or select a database in MongoDB?

18) What is a collection in MongoDB?

19) What is use of insertOne and insertMany in MongoDB?

20) What is sharding in MongoDB?

21) What is writeConcern in MongoDB?

22) What is use of upsert in MongoDB?

23) Explain what is Mongoose?

24) List some alternatives of MongoDB?

25) What is 32-bit nuances?

Q & A of MongoDB

1) What is use of capped collection in MongoDB?

Capped collections are fixed-size collections that restrict updates to the documents if the update results in increased document size and it ensures that the document size does not increase the size allocated on the disk.

2) What are Primary and Secondary Replica sets?

A replica set is a group of MongoDB instances that host the same data set. The primary is the only member in the replica set that receives write operations. Whereas Secondary members replicate this log and apply the operations to their data sets.

3) What is splitting in mongodb?

In MongoDb, Splitting is a process that keeps chunks from growing too large with the help of split command(). MongoDB splits the chunk, when a chunk grows beyond a specified chunk size, on the basis of shard key values the chunk represents.

4) What do you know about MongoDB?

MongoDB is a cross-platform document-oriented database program that is open source and free in nature. It can also be classified as the NoSQL database program. It was developed by MongoDB Inc. JSON-like documents with schema are used by MongoDB. Field, range queries, and regular expressions are also supported by MongoDB. The queries used by this contain user-defined JavaScript functions. It provides high availability with the replica sets. Fields can be indexed with primary and secondary indices. Sharding is used by MongoDB for scaling horizontally which determines how the data will be distributed. It can also be used as a file system with load balancing. It can also be used for batch processing of data.

5) Explain what is MongoDB?

MongoDB is an open-source NoSQL database management program that supports various forms of data. MongoDB is basically used as a tool that can manage document-oriented information, store or retrieve information. 
6) List some important features of MongoDB?

Some of the important features of MongoDB are as follows:
Support ad hoc queries. 
Indexing and Replication.
Duplication of data. 
Load balancing. 
Supports map reduction and aggregation tools.
Uses JavaScript instead of Procedures.
It is a schema-less database written in C++.

7) What is namespace in MongoDB?

A namespace is a canonical name for a collection or index in MongoDB. The namespace is basically a combination of the database name and the name of the collection or index, like so: [database-name]. [collection-or-index-name] .

8) What is BSON in MongoDB?

BSON stands for Binary JSON which is a binary serialization of JSON-like documents that is used by MongoDB to store the documents in a BSON format. BSON implementation is used for supporting embedding objects and arrays within other objects.

9) What type of DBMS is MongoDB?

MongoDB is an open-source NoSQL type DBMS or database management program that supports various forms of data.

10) What is the document structure of MongoDB?

MongoDB uses JSON format as the structure of the document. JSON documents support embedded fields, so related data and lists of data can be stored with the document instead of an external table.

11) What is replica set in MongoDB?

In MongoDB, a Replica Set is used to carry out MongoDB replication, which is a process of creating a copy of the same data set in more than one MongoDB server. A replica set is basically a group of MongoDB instances that maintain the same data set and pertain to any MongoDB process.

12) What is profiler in MongoDB?

In MongoDB, the database profiler collects detailed information about Database Commands executed against a running MongoDB instance. It writes all the data it collects to a system and captures and records data on the performance of write operations, cursors, and database commands on a running MongoDB instance.

13) Write the syntax for creating and droping a collection in MongoDB?

The syntax for creating and droping a collection in MongoDB are as follows:
Creating a Collection: collection_name. insert({key:value, key:value…})
Droping a Collection: db.collection.drop( { writeConcern: } )

14) What is the size limit of a document?

The maximum Document Size Limit in MongoDb is 16 megabytes or 16777216 bytes. The maximum document size helps ensure that a single document cannot use an excessive amount of RAM or, during transmission, an excessive amount of bandwidth.

15) What is _id Field in MongoDB?

In MongoDB, _id field is always the first field in the documents therefore each document stored in a collection requires a unique _id field that acts as a primary key.

16) Explain what is ObjectId in MongoDB?

An ObjectId in MongoDB is a 12-byte BSON type in which the first 4 bytes of the ObjectId represent the time in seconds then the next 3 bytes of the ObjectId represent the machine identifier then again the next 2 bytes are of process id and the last Field is 3 bytes used for increment the objectid.

17) Write syntax to create or select a database in MongoDB?

MongoDB uses DATABASE_NAME is used to create a database. The syntax of use DATABASE statement is as follows: use DATABASE_NAME

18) What is a collection in MongoDB?

In MongoDB, a collection is a grouping of documents such that documents within a collection can have different fields. A collection is the equivalent of a table in a relational database system and exists within a single database.

19) What is use of insertOne and insertMany in MongoDB?

In MongoDB, insertOne() is a method that is used whenever you want to insert a single document into your collection. It is basically used to insert a single document or record into the database. Whereas The insertMany() method inserts one or more documents in the collection. It takes an array of documents to insert into the collection.

20) What is sharding in MongoDB?

In MongoDB, Sharding is the process of distributing data across multiple hosts that is achieved by splitting large data sets into small data sets across multiple MongoDB instances. Basically, Sharding is used to store data across multiple machines.

21) What is writeConcern in MongoDB?

In MongoDB, write concern describes the level of acknowledgment requested from MongoDB for write operations to a standalone MongoDB or to replica sets or to sharded clusters, such that in sharded clusters, mongoose instances will pass the write concern on to the shards.

22) What is use of upsert in MongoDB?

MongoDB supports a feature known as upsert that mixes the functionality of an update with an insert. Upsert is an option that is used for update operation e.g. update(), findAndModify(), etc.

23) Explain what is Mongoose?

Mongoose is an Object Data Modeling or ODM library for MongoDB and Node. js. that manages relationships between data, provides schema validation and is used to translate between objects in code and the representation of those objects in MongoDB.

24) List some alternatives of MongoDB?

Some of the alternatives of MongoDB are:
JAM Stack - Fast, secure, and dynamic websites served without web servers.
PostgreSQL - SQL database is known for its reliability, features, and performance.
DynamoDB - NoSQL database created by Amazon Web Services (AWS)

25) What is 32-bit nuances?

In computer 32-bit nuances refer to the following:
There is extra memory-mapped file activity with journaling.
This will further constrain the limited db size of 32 bit builds.
Thus, for now, journaling by default is disabled on 32 bit systems.

26) What is __v field in Mongoose?

In Mongoose the “_v” field is the versionKey is a property set on each document when first created by Mongoose. This is a document inserted through the mongo shell in a collection and this key-value contains the internal revision of the document.

27) What is Projection Operators? List some Projection Operators available in MongoDB?

In MongoDB, projection operators are used for selecting only the necessary data rather than selecting the whole of the data of a document. Some of the Projection Operators available in MongoDB are:
$ - Projects the first element in an array that matches the query condition.
$elemMatch - Projects the first element in an array that matches the specified $elemMatch condition. 
$meta - Projects the available per-document metadata.
$slice - Limits the number of elements projected from an array. 

28) What is Bitwise Query Operator in MongoDB?

In MongoDb, Bitwise Query Operators are used to match numeric or binary values in which any bit from a set of bit positions has a value of 0 and 1.

29) Explain the structure of ObjectID in MongoDB?

In MongoDB, the structure of an ObjectId is consists of a 12-byte BSON type. This 12-byte structure can be distinguished as the first 4 bytes of the ObjectId represent the time in seconds since the UNIX epoch. Then the next 3 bytes of the ObjectId represent the machine identifier which is then followed by the next 2 bytes of the ObjectId represent the process ID.

30) What are Indexes in MongoDB?

In MongoDB, Indexes are a special data structure that supports the efficient execution of queries. It is used to store a small portion of the collection's data set in an easy way in order to traverse it. Indexes improve the speed of search operations in the database because instead of searching the whole document, the search is performed on the indexes that hold only a few fields.

31) What is a covered query in MongoDB?

In MongoDB, a covered query is a query that can be satisfied entirely using an index and does not have to examine any documents. Covered queries help us in querying data faster by ensuring the index created contains all the fields required by the query and it doesn't require examining any documents apart from the indexed ones.

32) What is Aggregation in MongoDB?

In MongoDb, the Aggregation operator is used to group the values from multiple documents together, such that it can perform a variety of operations on the grouped data to return a single result for example sum, average, minimum, maximum, etc are some of the operations performed on the grouped data to return a computed result. MongoDB provides three ways to perform aggregation: the aggregation pipeline, the map-reduce function, and single-purpose aggregation methods.

33) What is oplog?

The oplog stands for operations log which is a special capped collection that keeps a rolling record of all operations that modify the data stored in your databases. Oplog is a log of every internal operation used for replication in a MongoDB cluster.

34) What is Replication in MongoDB?

In MongoDB, replication is the process of creating a copy of the same data set in more than one MongoDB server that can be achieved by using a Replica Set. Where a replica set is a group of mongodb processes that maintain the same data set.

35) What is a Storage Engine in MongoDB?

In MongoDB, the storage engine is the component of the database that is responsible for managing how data is stored, both in memory and on disk. It is based on memory-mapped files and manages BSON data in memory and on disk to support read and write operations.

36) Explain what is GridFS?

In MongoDb, GridFS is a specification for storing and retrieving files that exceed the BSON-document size limit of 16 MB. It is used to store and retrieve large files such as images, audio files, video files, etc.

37) List the important features of MongoDB.

The important features of MongoDB are listed below: –
1. Aggregation framework– it uses aggregation framework for the batch processing of data and aggregation operations. It should be used in an effective manner.
2. The usage of BSON format in MongoDB– it uses the binary-encoded serialization of JSON-like documents. The data-types like- date and binary are supported in the format.
3. The sharing feature of MongoDB– using this feature, MongoDB supports the distribution of data across multiple machines. It supports deployment with large sets of data.
4. The Ad hoc queries in MongoDB– it supports field, range queries, and regular expressions.
5. Collections– MongoDB supports fixed size collection which can also be termed as capped collections.

38) Which all languages can be used with MongoDB?

Here goes a list of the languages which can be used with MongoDB: –
C
C++
C#
Java
Node.js
Perl
PHP
Python
Ruby
Scala
Go
Erlang.
Currently, MongoDB provides driver support for the languages listed above. It can be used easily with any of these languages.

39) What is the use of a namespace in MongoDB?

In MongoDB, a namespace is a combination of the database name and collection or index name. It is a canonical name for an index or a collection in MongoDB. A namespace consists of all the documents in MongoDB. The maximum length of a collection of namespaces is called the namespace length. It consists of the database name, a dot operator (.), and the name of the collection.
Syntax- <database>.<collection>
The namespace contains all the helper classes which can be used to construct various options which are to be used in the drivers. A namespace can also be termed as the concatenation of the collection name and the database name.

40) What do you mean by a replica set in MongoDB?

A group of mongo instances which is able to host the same data set is known as a replica set in MongoDB. A replica set consists of a primary node and a secondary node too. With the help of a replica set, all the data from primary node to the secondary node replicates. Replication is a process of synchronizing the data. Replication provides redundancy and it also increases the availability of data with the help of multiple copies of data on the different database server. It also protects the database from the loss of a single server.

41) What should all points be taken into consideration while creating a schema in MongoDB?

Following are the points which should be taken into consideration when you create a schema in MongoDB: –
Your schema should be designed according to your requirements.
If the objects are to be used together, you should combine them into one document. Otherwise, you should use them separately.
Joins should be performed while writing and not while reading.
If use cases are used more frequently, then you should optimize your schema.
Complex aggregation should be done in the schema.

42) What do you understand by a profiler with reference to MongoDB?

A database profiler is something which collects fine-grained data about write operations of MongoDB, the cursors, and the database commands. Profiling can be enabled on a per database or pre instance basis. When profiling is enabled, the profiling level also gets configurable. By default, the profiler will be off. All the data collected by the system.profiler collection is written by the database profiler to it. This collection is a capped collection. 0, 1, and 2, these are the three levels available in the database profiler. Profiling in a database can be enabled from the mongo shell or using a profile command through the driver. While enabling profiling, profiling level is also set. The profiler is used to record data in the system.profile collection.

43) Write the syntax for creating a collection and dropping a collection in MongoDB.

The creation of the collection is the basic step in MongoDB. Here is the syntax for creating a collection in MongoDB-
 Db.createCollection (name, options)
Dropping a collection basically means deleting a collection. Following is the syntax for dropping a collection in MongoDB-
Db.collection.drop()

44) What are the different types of NoSQL databases? Give some examples.

There are 4 basic types of NoSQL database. They are as follows: –
Key value store NoSQL database
Document store NoSQL database
Column store NoSQL database
Graph-based NoSQL database
The various examples of NoSQL database are- MongoDB, Cassandra, CouchDB, Hypertable, Redis, Riak, Neo4j, HBase, Couchbase, MemcacheDB, Voldemort, RevenDB, etc.

45) What are the differences between MongoDB and MySQL?

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.

46) Explain sharding in MongoDB?

    

47) List some alternatives to MongoDB?

   

48) I am getting error cannot overwrite model once compiled Mongoose, How to fix it?

   

49) What is the “__v” field in Mongoose?

When the mongoose is created at the first time the version key is a property set on every document. The value of this key comprises of the internal revision of the document. It is understood that the name of this document is configurable. The default key is __v

 MongoDB MCQs

1. The MongoDB is written in .................... language.

 C++

 Javascript

 C

 All of the above

 

2. Which of the foliowing is wrong statement -

 MongoDB supports search by field, range queries, regular expression searches

 MongoDB can store the business subject in the minimal number of documents

 Secondary indices is not available in MongoDB

 All of the above

 

3. In which year the MongoDB was Initial release?

 2008

 2009

 2010

 2011

 

4. A collection and a document in MongoDB is equivalent to............. concepts respectively.

 Table and Column

 Table and Row

 Column and Row

 Database and Table

 

5. in how much time the MongDB writes are written to the journal?

 100 s

 60 s

 1 s

 100 ms

 

6. Does MongoDB supports query joins between collections ?

 Yes

 No

 

7. what is MongoDB?

 data growth

 document database

 adminCommand

 Combine objects

 

8. The concatenation of the collection name and database name is called a -

 Namespace

 MongoDB

 sharding

 replica

 

9. What is the good alternatives to MongoDB?

 Redis & CouchDB

 Cassandra

 Riak & Hbase

 All of the mentioned

 

10. Which statements is correct about mongoose in MongoDB ?

 it is Java library to connect with MongoDB

 It is used for modeling your application data in node.js

 It is Python library to connect with MongoDB

 It is a PHP library to connect with MongoDB

 

11. Hidden member is used to support dedicated functions, such as backup or reporting.

 True

 False

 

12. A collection in MongoDB is a group of ......................

 Databases

 Related documents

 Schema

 Rows

 

13. Which is not a supported index type in MongoDB?

 TTL Index

 Neospatial

 Unique

 None of These

 

14. Which of the following is correct option ?

 MongoDB uses XML more in comparison with JSON

 MongoDB is column oriented data store

 MongoDB is a NoSQL database

 None of the above

 

15. Is MongoDB better than other SQL databases?

 Yes

 No

 

16. In which format MongoDB represents document structure?

 BSON

 .txt

 .Docx

 None of these

 

17. Howmany byte counter in BSON is starting with a random value ?

 4

 2

 3

 None of the above

 

18. which field is always the first field in the document.?

 _id

 Ob_id

 id

 None of these

 

19. The application, that communicates with application MongoDB by way of a client library, is called _________________ .

 Parent

 Driver

 Rank

 None of the above

 

20. _____________________sorting is not supported by MongoDB.

 collection

 collation

 heap

 none of the mentioned

 

21. When a relational expression is false, it has the value ________.

 zero

 one

 

22. In mongodb, there is a similar feature of 'like' expression as like rdbms.

 True

 False

23. MongoDB Queries can return specific fields of documents which also include user-defined __________ functions.
a) Javascript
b) C
c) C++
d) All of the mentioned

24. Point out the wrong statement.
a) Secondary indices are not available in MongoDB
b) MongoDB supports search by field, range queries, regular expression searches
c) MongoDB can store the business subject in the minimal number of documents
d) All of the mentioned

25. MongoDB has been adopted as ________ software by a number of major websites and services.
a) frontend
b) backend
c) proprietary
d) all of the mentioned

26. MongoDB is a _________ database that provides high performance, high availability, and easy scalability.
a) graph
b) key value
c) document
d) all of the mentioned

27. Dynamic schema in MongoDB makes ____________ easier for applications.
a) inheritance
b) polymorphism
c) encapsulation
d) none of the mentioned

28. With ________ MongoDB supports a complete backup solution and full deployment monitoring.
a) MMS
b) AMS
c) CMS
d) DMS

Explanation: MMS stands for MongoDB Management Service and is available to all users in the cloud and on-premises as part of MongoDB Standard and Enterprise Subscriptions.

 

MongoDB Interview Questions MongoDB Interview Questions Reviewed by Asst. Prof. Sunita Rai, Computer Sci.. Dept., G.N. Khalsa College, Mumbai on January 16, 2022 Rating: 5

No comments:

Powered by Blogger.