Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
January 7, 2021 10:01 am GMT

MongoDB interview questions (answered) for fullstack developers

MongoDB is the trending NoSQL database, with significant adoption among the Fortune 500 and Global 500. Follow along and check our list of 83 common MongoDB interview questions and answers and get ready for your next NoSQL developer interview in 2021.

You can find all 83 answers here https://devinterview.io/dev/mongodb-interview-questions

1. Explain what is MongoDB?

Answer:

MongoDB is an open-source document database that provides high performance, high availability, and automatic scaling. It's Key Features are:

  • Document Oriented and NoSQL database.
  • Supports Aggregation
  • Uses BSON format
  • Sharding (Helps in Horizontal Scalability)
  • Supports Ad Hoc Queries
  • Schema Less
  • Capped Collection
  • Indexing (Any field in MongoDB can be indexed)
  • MongoDB Replica Set (Provides high availability)
  • Supports Multiple Storage Engines

Source:mongodb.com

2. How many indexes does MongoDB create by default for a new collection?

Answer:

By default, MongoDB created the _id collection for every collection.

Source:tutorialspoint.com

3. Which are the most important features of MongoDB?

Answer:

  • Flexible data model in form of documents
  • Agile and highly scalable database
  • Faster than traditional databases
  • Expressive query language

Source:tutorialspoint.com

4. When should we embed one document within another in MongoDB?

Answer:

You should consider embedding documents for:

  • contains relationships between entities
  • One-to-many relationships
  • Performance reasons

Source:tutorialspoint.com

5. Compare SQL databases and MongoDB at a high level

Answer:

SQL databases store data in form of tables, rows, columns and records. This data is stored in a pre-defined data model which is not very much flexible for today's real-world highly growing applications. MongoDB in contrast uses a flexible structure which can be easily modified and extended.

Source:tutorialspoint.com

6. If you remove an object attribute, is it deleted from the database?

Answer:

Yes, it be. Remove the attribute and then re-save () the object.

Source:medium.com/@hub4tech

7. Does MongoDB need a lot space of Random Access Memory (RAM)?

Answer:

No. MongoDB can be run on small free space of RAM.

Source:medium.com/@hub4tech

8. Why does Profiler use in MongoDB?

Answer:

MongoDB uses a database profiler to perform characteristics of each operation against the database. You can use a profiler to find queries and write operations

Source:medium.com/@hub4tech

9. What is Namespace in MongoDB?

Answer:

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

Source:medium.com/@hub4tech

10. What are Indexes in MongoDB?

Answer:

Indexes support the efficient execution of queries in MongoDB. Without indexes, MongoDB must perform a collection scan, i.e. scan every document in a collection, to select those documents that match the query statement. If an appropriate index exists for a query, MongoDB can use the index to limit the number of documents it must inspect.

Source:tutorialspoint.com

11. What is BSON in MongoDB?

Answer:

BSON is a binary serialization format used to store documents and make remote procedure calls in MongoDB. BSON extends the JSON model to provide additional data types, ordered fields, and to be efficient for encoding and decoding within different languages.

Source:mongodb.com

12. What is a replica set?

Answer:

It is a group of mongo instances that maintain same data set. Replica sets provide redundancy and high availability, and are the basis for all production deployments.

The ideas of a replicaset are :

  • Every data are repartited on each node
  • Only one node accept writes

Source:interviewbubble.com

13. What Is Replication In MongoDB?

Answer:

Replication is the process of synchronizing data across multiple servers. Replication provides redundancy and increases data availability. With multiple copies of data on different database servers, replication protects a database from the loss of a single server. Replication also allows you to recover from hardware failure and service interruptions.

Source:interviewbubble.com

14. Mention the command to insert a document in a database called school and collection called persons.

Answer:

    use school;    db.persons.insert( { name: "kadhir", dept: "CSE" } )
Enter fullscreen mode Exit fullscreen mode

Source:tutorialspoint.com

15. Explain the structure of ObjectID in MongoDB

Answer:

ObjectIds are small, likely unique, fast to generate, and ordered. ObjectId values consist of 12 bytes, where the first four bytes are a timestamp that reflect the ObjectIds creation. Specifically:

  • a 4-byte value representing the seconds since the Unix epoch,
  • a 5-byte random value, and
  • a 3-byte counter, starting with a random value. In MongoDB, each document stored in a collection requires a unique _id field that acts as a primary key. If an inserted document omits the _id field, the MongoDB driver automatically generates an ObjectId for the _id field.

Source:mongodb.com

16. Why MongoDB is not preferred over a 32-bit system?

Answer:

When running a 32-bit build of MongoDB, the total storage size for the server, including data and indexes, is 2 gigabytes. For this reason, do not deploy MongoDB to production on 32-bit machines.

If you're running a 64-bit build of MongoDB, there's virtually no limit to storage size.

Source:tutorialspoint.com

17. Does MongoDB pushes the writes to disk immediately or lazily?

Answer:

MongoDB pushes the data to disk lazily. It updates the immediately written to the journal but writing the data from journal to disk happens lazily.

Source:tutorialspoint.com

18. When to use MongoDB or other document oriented database systems?

Answer:

MongoDB is best suitable to store unstructured data. And this can organize your data into document format. These data stores don't enforce the ACID properties, and any schemas. This doesn't provide any transaction abilities. So this can scale big and we can achieve faster access (both read and write). If you wanted to work with structured data you can go ahead with RDBM.

Source:stackoverflow.com

19. What is sharding?

Answer:

Sharding means to store the data on the multiple machines.

Source:interviewbubble.com

20. What is use of capped collection in MongoDB?

Answer:

Capped collections allow you to define a fix length/size collection. After the size/no of documents have been reached it will override the oldest document to accommodate new documents. It is like a circular buffer. Capped collections support high-throughput operations that insert and retrieve documents based on insertion order.

Consider the following potential use cases for capped collections:

  • Store log information generated by high-volume systems. Inserting documents in a capped collection without an index is close to the speed of writing log information directly to a file system.
  • Cache small amounts of data in a capped collections.

Source:stackoverflow.com

Explore more dev interview question here https://devinterview.io/


Original Link: https://dev.to/devinterview/mongodb-interview-questions-answered-for-fullstack-developers-3hpn

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To