MongoDB Interview Questions and Answers
Question - 91 : - What is the syntax of the limit() and sort() method?
Answer - 91 : -
Syntax of the limit() method is:
- >db.COLLECTION_NAME.find().limit(NUMBER)
Syntax of the sort() method is:
- >db.COLLECTION_NAME.find().sort({KEY:1})
Question - 92 : - What do you know about NoSQL databases? What are the various types of NoSQL databases?
Answer - 92 : -
NoSQL refers to “Not Only SQL”. NoSQL is a kind of database that handles and sorts all kinds of structured, massive, and difficult data. It is a new method to think about databases. Kinds of NoSQL databases:
- Key-Value
- Graph
- Column Oriented
- Document Oriented
Question - 93 : - Which command do we use for dropping a database?
Answer - 93 : -
We use the “DB.drop database” command for dropping a database.
Question - 94 : - Explain MongoDB Projection
Answer - 94 : -
In MongoDB, we use Projection for selecting only the required data. It will not select the complete data of a document.
Question - 95 : - Why do we use the pretty() method?
Answer - 95 : -
We use the pretty() method for displaying the results in a formatted way.
Question - 96 : - How do we remove a document from the collection?
Answer - 96 : -
By using the remove() method, we remove a document from the collection.
Question - 97 : - What are the points we should consider while creating a schema in MongoDB?
Answer - 97 : -
We must consider the following points while creating a schema:
- Designing the Scheme based on the user requirements.
- Combining the objects into one document, if we have to use them jointly, or else, separate them.
- Perform joins while on write, and not while it is reading.
- For most general application scenarios, maximize the schema.
- Perform complex aggregations in the schema.
Question - 98 : - What does ObjectId contain?
Answer - 98 : -
ObjectId contains the following:
- Client machine ID
- Client process ID
- Byte incremented counter
- Timestamp
Question - 99 : - Explain Vertical Scaling and Horizontal Scaling?
Answer - 99 : -
- Vertical Scaling: Vertical Scaling increases storage and CPU resources for expanding the capacity.
- Horizontal Scaling: Horizontal Scaling splits the datasets and circulates the data over multiple shards or servers.
Question - 100 : - What are the elements of the Sharded Cluster?
Answer - 100 : -
Following are the elements of the Sharded Cluster:
- Query routers
- Shards
- Config servers