Explore essential concepts of CouchDB JSON document storage with this quiz. Assess your understanding of document structure, storage mechanisms, unique identifiers, data formats, and related terminology while clarifying common misconceptions around working with JSON data in document-based databases.
Which key must be present in every JSON document stored in CouchDB to uniquely identify it?
Explanation: The correct key is '_id', which is required for uniquely identifying each document stored. The terms 'docID', 'uniqueKey', and 'identifier' are not recognized as mandatory identifiers in this context, though they sound plausible. They may be confused with '_id' due to their similar meanings, but only '_id' is officially required. Using any other term will not satisfy the identification standard set for the storage system.
In CouchDB, which format must all stored documents strictly follow?
Explanation: All documents in CouchDB must be stored in the JSON (JavaScript Object Notation) format, which enables flexibility and schema-free storage. XML, YAML, and CSV are common data formats elsewhere but are not valid for direct document storage in this environment. Attempts to use XML, YAML, or CSV will result in errors or misinterpretation by the storage engine, as only JSON is supported.
What is the consequence if two documents in CouchDB have the same '_id' value?
Explanation: If two documents have the same '_id', the newer write will overwrite the previous document with that identifier. They are not stored as separate entities because IDs must be unique. No error is thrown and data merging does not occur by default, making 'one overwrites the other' the only correct answer. The distractors misunderstand how document identification and storage work.
Which of these represents a valid JSON property name in a CouchDB document?
Explanation: _rev is the correct answer as it is a special system property tracking the current document revision. The options 'rev#', 'doc.rev', and 'rev-id' are not recognized or used as standard property names. These distractors introduce invalid characters or incorrect naming conventions not used for built-in document properties.
How does CouchDB typically store binary data, like images or PDFs, within a document?
Explanation: Binary data is stored as attachments to documents, allowing separation from the main JSON content. Plain JSON fields cannot contain raw binary data, and XML tags are not used in this context. Compressing data into text is not a standard technique for handling binary data in CouchDB, so only the 'attachments' approach is valid.
What happens to the '_rev' property when a CouchDB document is updated?
Explanation: With each document update, the '_rev' property is replaced by a new revision value, tracking the latest version. It does not remain stagnant or get removed, nor does it become an array. The other options misrepresent the purpose of this value, which ensures data consistency through versioning.
Which statement best describes how CouchDB handles document schema?
Explanation: CouchDB is schema-free, allowing documents to have different structures and fields as needed. There is no requirement for strict schemas or identical fields, and field names are not restricted to those starting with underscores. The incorrect options reflect common misconceptions about schema enforcement.
Which field prefix in CouchDB JSON documents is usually reserved for special system properties?
Explanation: Fields that start with an underscore are reserved for special system properties, such as '_id' and '_rev'. Prefixes like 'sys-', '$', and 'meta.' are not reserved or treated specially in standard JSON documents. The distractors may be used for naming, but they do not have reserved status or special meaning.
What is the typical way to retrieve a single document by its unique identifier in CouchDB?
Explanation: Retrieval is most efficiently performed using the document's '_id' since this is the unique identifier. Searching other fields, using '_rev', or querying and filtering all documents is slower and less efficient. The distractors suggest methods that are possible but not the intended or optimal approach.
What happens if you attempt to store an invalid JSON document, such as one with missing quotes around property names, in CouchDB?
Explanation: Invalid JSON documents are rejected to maintain data integrity and ensure proper processing. The system does not automatically correct or convert invalid data. Storing as plain text or accepting but restricting access is not standard behavior. The distractors imply leniency not present in the validation process.