Mongo DB - interview questions Flashcards
What is MongoDB?
A: Mongo-DB is a document database that provides high performance, high availability and easy scalability.
Q: What is “Namespace” in MongoDB?
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.
Q: Explain what is a replica set?
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.
Q: 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 databases. Replication helps in protecting the database from the loss of a single server.
Q: While creating Schema in MongoDB what are the points need to be taken into consideration?
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
Q: 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()
Q: What is the command syntax for inserting a document?
A: For inserting a document command syntax is database.collection.insertOne (document). And database.collection.insertMany (document).
Q: What is the basic syntax to use the index in MongoDB?
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.
Q: What is BSON in MongoDB?
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.
Q: What is a collection in MongoDB?
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.
Q: What is writeConcern?
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.
Q: What is Storage Engine? What are all the Storage Engines available in MongoDB?
A: WiredTiger Storage Engine:
In-Memory Storage Engine
MMAPv1 Storage Engine
Q: What are the different types of NoSQL databases? Give some examples.
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
Q: What is Embedded Documents and Normalized data models Documents in MongoDB?
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