Which TWO of the following statements accurately describe the characteristics of MongoDB documents?
Trap 1: Documents can contain up to 64MB of data.
The maximum size for a single BSON document is 16MB. This constraint exists to prevent memory exhaustion and encourage developers to design better data models. If data exceeds this size, it should be distributed across multiple documents or stored in GridFS to maintain optimal database performance and integrity.
Trap 2: The order of fields within a document is always strictly preserved.
While MongoDB preserves the order of fields in most scenarios, it does not guarantee that the order will remain identical after updates or operations. Applications should never rely on field order for business logic. Relying on field order can lead to bugs and data inconsistencies during database maintenance cycles.
Trap 3: Field names can contain any character, including null bytes.
Field names have restrictions; for instance, they cannot contain the null character. Additionally, field names starting with a dollar sign ($) are reserved for internal operators. Violating these naming conventions will result in errors when attempting to insert or update documents, potentially breaking the application's data persistence logic.
- A
Documents can contain up to 64MB of data.
Why it fails: The maximum size for a single BSON document is 16MB. This constraint exists to prevent memory exhaustion and encourage developers to design better data models. If data exceeds this size, it should be distributed across multiple documents or stored in GridFS to maintain optimal database performance and integrity.
- B
Documents within the same collection can have different fields.
MongoDB is a schema-flexible database. This means that documents within a single collection do not need to share the same structure. This flexibility allows developers to evolve their data models over time without needing costly schema migrations or downtime, providing significant agility for rapidly changing application requirements.
- C
The order of fields within a document is always strictly preserved.
Why it fails: While MongoDB preserves the order of fields in most scenarios, it does not guarantee that the order will remain identical after updates or operations. Applications should never rely on field order for business logic. Relying on field order can lead to bugs and data inconsistencies during database maintenance cycles.
- D
Every document must contain an '_id' field.
Every document must have a unique '_id' field that acts as the primary key. If a document is inserted without this field, the MongoDB driver or server automatically generates an ObjectId. This ensures that every document in the collection is uniquely identifiable for efficient lookup and modification operations.
- E
Field names can contain any character, including null bytes.
Why it fails: Field names have restrictions; for instance, they cannot contain the null character. Additionally, field names starting with a dollar sign ($) are reserved for internal operators. Violating these naming conventions will result in errors when attempting to insert or update documents, potentially breaking the application's data persistence logic.