InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
When to use MongoDB? |
|
Answer» You should use MongoDB when you are building internet and business applications that need to evolve quickly and scale elegantly. MongoDB is popular with developers of all kinds who are building scalable applications using agile methodologies.
|
|
| 2. |
What are the data types in MongoDB? |
|
Answer» MongoDB supports a wide range of data types as values in documents. Documents in MongoDB are similar to objects in JavaScript. ALONG with JSON’s essential key/value–pair nature, MongoDB adds SUPPORT for a number of additional data types. The common data types in MongoDB are:
|
|
| 3. |
How to perform queries in MongoDB? |
|
Answer» The find method is used to PERFORM queries in MongoDB. Querying returns a subset of documents in a collection, from no documents at all to the entire collection. Which documents GET returned is DETERMINED by the first argument to find, which is a DOCUMENT specifying the query criteria. Example: |
|
| 4. |
How do you Delete a Document? |
|
Answer» The CRUD API in MONGODB provides deleteOne and deleteMany for this PURPOSE. Both of these methods TAKE a filter document as their first parameter. The filter specifies a set of criteria to match against in removing documents. |
|
| 5. |
How do you Update a Document? |
|
Answer» Once a document is stored in the database, it can be changed USING one of several UPDATE methods: updateOne, updateMany, and replaceOne. updateOne and updateMany each takes a filter document as their first parameter and a modifier document, which describes changes to make, as the second parameter. replaceOne also takes a filter as the first parameter, but as the second parameter replaceOne expects a document with which it will replace the document matching the filter. For example, in order to replace a document: { "_id" : ObjectId("4b2b9f67a1f631733d917a7a"), "NAME" : "alice", "friends" : 24, "enemies" : 2} |
|
| 6. |
How to add data in MongoDB? |
|
Answer» The BASIC method for adding DATA to MongoDB is “inserts”. To insert a single document, use the collection’s insertOne method: > db.books.insertOne({"TITLE" : "START With Why"})For inserting multiple documents into a collection, we use insertMany. This method enables passing an ARRAY of documents to the database. |
|
| 7. |
What are some features of MongoDB? |
Answer»
|
|
| 8. |
How does Scale-Out occur in MongoDB? |
|
Answer» The document-oriented data model of MongoDB makes it EASIER to split data across multiple servers. Balancing and loading data across a cluster is done by MongoDB. It then redistributes documents automatically. |
|
| 9. |
What is the Mongo Shell? |
|
Answer» It is a JavaScript shell that allows interaction with a MongoDB instance from the COMMAND LINE. With that one can perform administrative functions, inspecting an instance, or EXPLORING MongoDB. To start the shell, run the mongo EXECUTABLE: $ mongod$ mongoMongoDB shell version: 4.2.0connecting to: test>The shell is a full-featured JavaScript interpreter, capable of running arbitrary JavaScript programs. Let’s see how basic math works on this: > x = 100;200> x / 5;20 |
|
| 10. |
What are Databases in MongoDB? |
|
Answer» MONGODB groups collections into DATABASES. MongoDB can host several databases, each grouping TOGETHER collections. |
|
| 11. |
What is a Collection in MongoDB? |
|
Answer» A collection in MongoDB is a group of documents. If a document is the MongoDB analog of a row in a relational database, then a collection can be thought of as the analog to a table. |
|
| 12. |
What is a Document in MongoDB? |
|
Answer» A Document in MongoDB is an ORDERED SET of keys with associated values. It is represented by a map, hash, or dictionary. In JavaScript, DOCUMENTS are represented as objects: Complex documents will contain MULTIPLE key/value pairs: |
|
| 13. |
What are some of the advantages of MongoDB? |
|
Answer» Some advantages of MongoDB are as follows:
|
|