Schema for CSFLE with null values

Hi,

I am trying to use Client-Side-Field-Level-Encryption (CSFLE) ; So far I am providing the schemaMap in the autoEncryption property when I initialize my Mongo Client (which is the native NodeJs driver).

However my schema has a spec which is I want to encrypt a single field from an object, but, the object itself may be null.

My latest tries were as follow :

{
  'database.customers': {
    bsonType: 'object',
    encryptMetadata: {
      keyId: [new Binary(Buffer.from("KEYID", "hex"), 4)]
    },
    properties: {
      name: {
        bsonType: [ 'object', 'null' ],
        anyOf: [
          { bsonType: 'null' },
          {
            bsonType: 'object',
            properties: {
              value: {
                encrypt: {
                  algorithm: 'AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic',
                  bsonType: 'string'
                }
              }
            }
          }
        ]
      }
    }
  }
}

Which ends up with Invalid schema containing the 'encrypt' keyword. The documentation of course does not cover such special case. It seems the keyword anyOf is supported for Mongo schemas and CSFLE does not say the support it’s dropped for encryption.

If anyone may point out a lead to solve that, i would be thankful.

Thank you,
Best regards

1 Like

Hello. Did you manage to fix it?