Cast encrypted fields to native BSON types (int, long, double) instead of strings

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Summary

      Automatic encryption encrypts a value according to the bsonType declared in the encryptedFieldsMap. Values that arrive as strings (HTTP form fields, JSON APIs, CSV imports) do not match the native BSON types int / long / double. For an encrypted field declared bsonType: "int" or bsonType: "double", a string such as "1500" must be coerced manually ((int), (float), a mutator, or a custom cast) before it is saved. With Queryable Encryption, a value that does not match the declared type is rejected by the driver or the server, so the coercion is required.

      This ticket proposes that laravel-mongodb cast attributes to the native BSON types declared in the encryptedFieldsMap, at least int, long, and double, so form and JSON strings become the expected type automatically rather than being stored as strings or rejected.

      Proposed approach

      • Derive an Eloquent cast from bsonType: int -> integer, double -> float, long -> int, date -> date, object -> array, bool -> boolean.
      • Apply it on write so the driver receives the native BSON type, not a string.
      • Surface conflicts with a user-declared cast on the same field.
      • Keep the existing read-side integer / float semantics.

      Related

      • Epic: PHPLARA-50. This is linked as a follow-up to that epic.

              Assignee:
              Unassigned
              Reporter:
              Jérôme Tamarelle
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated: