Mongo DB - interview questions Flashcards

1
Q

What is MongoDB?

A

A: Mongo-DB is a document database that provides high performance, high availability and easy scalability.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Q: What is “Namespace” in MongoDB?

A

A: MongoDB stores BSON (Binary Interchange and Structure Object Notation) objects in the collection. The concatenation of the collection name and database name is called a namespace.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Q: Explain what is a replica set?

A

A: A replica set is a group of mongo instances that host the same data set. In a replica set, one node is primary, and another is secondary. From primary to the secondary node all data replicates.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Q: How replication works in MongoDB?

A

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 databases. Replication helps in protecting the database from the loss of a single server.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Q: While creating Schema in MongoDB what are the points need to be taken into consideration?

A

A: Points need to be taken into 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 schema

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Q: What is the command syntax for inserting a document?

A

A: For inserting a document command syntax is database.collection.insertOne (document). And database.collection.insertMany (document).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Q: What is the basic syntax to use the index in MongoDB?

A

Q: What is the basic syntax to use the index in MongoDB?
A: The basic syntax to use in MongoDB is >db.COLLECTION_NAME.ensureIndex ( {KEY:1} ). Here the key is the name of the COLUMN (or KEY:VALUE pair) which is present in the documents.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Q: What is BSON in MongoDB?

A

A: MongoDB stores data as BSON documents. BSON is a binary representation of JSON documents, though it contains more data types than JSON. Some of the supported data types are Double, String, Object, Array, Binary Data, RegEx, Boolean, Date, Null, JavaScript, Timestamp. ObjectId.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Q: What is a collection in MongoDB?

A

A: A collection is a group of documents. If a document is the MongoDB analog of a row in a relational database, then collection is the analog to a table.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Q: What is writeConcern?

A

A: Whenever we query the database to insert (), insertOne() or insertMany(), we can pass an additional parameter which is writeConcern. It is a document describes the level of acknowledgment requested from MongoDB for write operations. Write concern can include the following fields:

  • the w option to request acknowledgment that the write operation has propagated to a specified number of MongoDB instances or to MongoDB instances with specified tags.
  • the j option to request acknowledgment that the write operation has been written to the journal, and
  • the timeout option to specify a time limit to prevent write operations from blocking indefinitely.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Q: What is Storage Engine? What are all the Storage Engines available in MongoDB?

A

A: WiredTiger Storage Engine:
In-Memory Storage Engine
MMAPv1 Storage Engine

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Q: What are the different types of NoSQL databases? Give some examples.

A
A: There are 4 basic types of NoSQL databases. They are as follows: –
•	Key-value store NoSQL database
•	Document store NoSQL database
•	Column store NoSQL database
•	Graph-based NoSQL database
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Q: What is Embedded Documents and Normalized data models Documents in MongoDB?

A

A: Normalized data models describe relationships using references between documents. In general, use normalized data models

You may embed related data in a single structure or document. These schemas are generally known as “denormalized” models, and take advantage of MongoDB’s rich documents. Embedded data models allow applications to store related pieces of information in the same database record. As a result, applications may need to issue fewer queries and updates to complete common operations

How well did you know this?
1
Not at all
2
3
4
5
Perfectly