Technology Encyclopedia Home >What are the restrictions on the database document field format?

What are the restrictions on the database document field format?

Database document field formats have several restrictions depending on the database type and storage engine. Here’s a breakdown with examples:

  1. Data Type Limitations:

    • Fields must adhere to predefined data types (e.g., string, number, boolean, date).
    • Example: In a NoSQL database like MongoDB (or Tencent Cloud’s TCB DocumentDB), a field cannot store a binary file directly unless it’s encoded (e.g., Base64).
  2. Size Constraints:

    • Fields often have maximum size limits. For example, a string field might be capped at 16MB (MongoDB’s document size limit).
    • Example: Storing a 20MB JSON object in a single field would exceed MongoDB’s limit, requiring chunking or external storage (Tencent Cloud COS for large files).
  3. Indexing Restrictions:

    • Indexed fields may have length limits (e.g., MongoDB’s indexed strings are capped at 1024 bytes).
    • Example: A 2000-character string field cannot be fully indexed if the limit is 1024 bytes.
  4. Special Character Handling:

    • Some databases restrict special characters in field names (e.g., MongoDB disallows . and $ in field names).
    • Example: A field named user.name must be renamed to user_name to comply with MongoDB’s rules.
  5. Nested Structure Limits:

    • Deeply nested documents may hit performance or size limits.
    • Example: A document with 100 nested levels might cause query slowdowns or errors in some databases.

For large file storage in Tencent Cloud, use Tencent Cloud Object Storage (COS) instead of embedding files in documents. For structured data, Tencent Cloud TCB DocumentDB (compatible with MongoDB) enforces these rules while providing scalability.