MongoDB interview questions and answers
1. What do you know about MongoDB?
2. List the important features of MongoDB.
- Aggregation framework– it uses aggregation framework for the batch processing of data and aggregation operations. It should be used in an effective manner.
- 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.
- 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.
- The Ad hoc queries in MongoDB– it supports field, range queries, and regular expressions.
- Collections– MongoDB supports fixed size collection which can also be termed as capped collections.
3. Which all languages can be used with MongoDB?
Currently, MongoDB provides driver support for the languages listed above. It can be used easily with any of these languages.
4. 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.
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.
5. What do you mean by a replica set in MongoDB?
6. What should all points be taken into consideration while creating 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.
7. What do you understand by a profiler with reference to MongoDB?
8. Write the syntax for creating a collection and dropping 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-
9. What are the different types of NoSQL databases? Give some examples.
- Key value store NoSQL database
- Document store NoSQL database
- Column store NoSQL database
- Graph-based NoSQL database
10. What are the differences between MongoDB and MySQL?
- 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.