Skip to content

Interview-expert/mongodb-interview-questions

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 

Repository files navigation

πŸ–² Top 83 MongoDB interview questions (answered) for developers in 2021

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 also 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" } )
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 ObjectId’s 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?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 17. Does MongoDB pushes the writes to disk immediately or lazily?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 18. When to use MongoDB or other document oriented database systems?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 19. What is sharding?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 20. What is use of capped collection in MongoDB?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 21. What is the difference between MongoDB and MySQL?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 22. Does Mongodb Support Foreign Key Constraints?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 23. Why are MongoDB data files large in size?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 24. What is the difference b/w MongoDB and CouchDB?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 25. Can you create an index on an array field in MongoDB? If yes, what happens in this case?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 26. If you remove a document from database, does MongoDB remove it from disk?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 27. What is Sharding in MongoDB?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 28. Should I normalize my data before storing it in MongoDB?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 29. What does MongoDB not being ACID compliant really mean?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 30. When to use CouchDB over MongoDB and vice versa?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 31. How is MongoDB better than other SQL databases?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 32. How can you achieve transaction and locking in MongoDB?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 33. How can you achieve primary key - foreign key relationships in MongoDB?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 34. What is oplog?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 35. What is a covered query in MongoDB?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 36. Is there an β€œupsert” option in the mongodb insert command?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 37. Explain advantages of BSON over JSON in MongoDB?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 38. Does MongoDB support ACID transaction management and locking functionalities?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 39. How is data stored in MongoDB?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 40. Can one MongoDB operation lock more than one databases? If yes, how?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 41. What is Aggregation in MongoDB?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 42. What is BSON and exactly how is it different from JSON?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 43. What is a cluster in MongoDB?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 44. Mention the command to check whether you are on the master server or not.

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 45. How can I combine data from multiple collections into one collection?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 46. How do I perform the SQL JOIN equivalent in MongoDB?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 47. How to query MongoDB with %like%?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 48. Find objects between two dates MongoDB

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 49. How to query MongoDB with β€œlike”?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 50. What happens if an index does not fit into RAM?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 51. Mention the command to list all the indexes on a particular collection

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 52. How can you isolate your cursors from intervening with the write operations?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 53. Explain what is horizontal scalability?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 54. How does MongoDB provide concurrency?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 55. How does Journaling work in MongoDB?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 56. Is MongoDB schema-less?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 57. When to Redis or MongoDB?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 58. How replication works in MongoDB?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 59. What are alternatives to MongoDB?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 60. Where can I run MongoDB?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 61. At what interval does MongoDB write updates to the disk?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 62. What are Primary and Secondary Replica sets?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 63. Why is a covered query important?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 64. Does MongoDB provide a facility to do text searches? How?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 65. How does MongoDB ensure high availability?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 66. What's the advantage of the backup features in Ops Manager versus traditional backup strategies?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 67. Where does MongoDB stand in the CAP theorem?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 68. Which are the two storage engines used by MongoDB?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 69. What are three primary concerns when choosing a data management system?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 70. How much faster is Redis than MongoDB?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 71. What is a Storage Engine in MongoDB

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 72. What is splitting in MongoDB?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 73. How to condense large volumes of data in Mongo?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 74. What are the differences between MongoDB and MySQL?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 75. Update MongoDB field using value of another field

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 76. How to check if a field contains a substring?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 77. How to get the last N records from find?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 78. MongoDB relationships. What to use - embed or reference?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 79. How to remove a field completely from a MongoDB document?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 80. By default, MongoDB writes and reads data from both primary and secondary replica sets. True or False.

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 81. How to find MongoDB records where array field is not empty?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 82. Is it possible to update MongoDB field using value of another field?

πŸ‘‰πŸΌ Check all 83 answers


πŸ”Ή 83. How to find document with array that contains a specific value?

πŸ‘‰πŸΌ Check all 83 answers


About

🟣 MongoDB Interview Questions Answered to help you get ready for your next full-stack developer interview.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published