03 / 12

What is a dcoument in NoSQL database?

Difficulty: 4/10
document structure, schema flexibility, storage limits

A document in MongoDB is equivalent to a row in a table in RDBMS. Documents are stored in BSON format and are gathered together in collections.

  1. 1

    It is a data structure composed of field and value pairs. MongoDB documents are similar to JSON objects. The values of fields may include other documents, arrays, and arrays of documents.

  2. 2

    Documents correspond to native data types in many programming languages.

  3. 3

    Embedded documents and arrays reduce need for expensive joins.

Scenario Questions

0-2 years experience

  1. 1We need to store a user profile with name, email, and a list of addresses. How would you model that as a MongoDB document and what would the JSON look like?
  2. 2What happens if you try to insert a document that exceeds MongoDB's 16 MB BSON size limit?
  3. 3How would you write a query to return only the 'email' field from every document in the users collection?

2-5 years experience

  1. 1A query on the orders collection is doing a full collection scan even though there's an index on customerId. Explain why the index might be ignored because of document design and how you'd fix it.
  2. 2During a feature rollout, some existing documents are missing a newly added 'status' field, causing the app to crash. How would you debug and remediate this without downtime?
  3. 3You need to add a new field to millions of existing documents. What strategies would you use to roll out the change safely in MongoDB?

5-8 years experience

  1. 1Design a sharding strategy for a high‑traffic events collection where each document can be several megabytes. Discuss how document size and schema affect shard‑key choice and balancing.
  2. 2Your service is suffering because documents contain very large embedded arrays. How would you refactor the schema, and what trade‑offs does moving to a referencing model introduce?
  3. 3Explain how the document model influences backup and restore times at petabyte scale, and what design choices can mitigate the impact.

8+ years experience

  1. 1We're migrating a legacy relational system to MongoDB. How would you decide which tables become single documents versus multiple related collections, considering future query patterns and data growth?
  2. 2Multiple teams store audit logs as documents with varying schemas. How would you establish a governance model to ensure consistency, queryability, and compliance over time?
  3. 3If we need multi‑tenant isolation while sharing the same MongoDB cluster, how would you structure documents and collections to balance security, performance, and operational overhead?

Follow-up Questions

  • Can you walk me through a concrete example where you chose embed versus reference?
  • What are the practical limits you keep in mind when designing a document schema?
  • How would you monitor the impact of your document design on query latency?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.