I have been following this guide - How to use MongoDB Client-Side Field Level Encryption (CSFLE) with Node.js/ to test out the MongoDB CSFLE.
In doing so, in the step of creating the data key in local key vault store https://developer.mongodb.com/how-to/client-side-field-level-encryption-csfle-mongodb-node/#create-a-data-key-in-mongodb-for-encrypting-and-decrypting-document-fields the data key successfully is created but the keyAltName is not attached to the data key’s document.
I tested this multiple times and there is nothing wrong in my code and I’m following the guide as it is. I can’t understand what is causing this issue. The data key creation is successful but without the keyAltNames field. A help here would be really appreciated.
The code related to Data Key Document Creation
async findOrCreateDataKey(client) {
const encryption = new ClientEncryption(client, {
keyVaultNamespace: this.keyVaultNamespace,
kmsProviders: this.kmsProviders
})
await this.ensureUniqueIndexOnKeyVault(client)
let dataKey = await client
.db(this.keyDB)
.collection(this.keyColl)
.findOne({ keyAltNames: { $in: [this.keyAltNames] } })
if (dataKey === null) {
dataKey = await encryption.createDataKey("local", {
keyAltNames: [this.keyAltNames]
})
return dataKey.toString("base64")
}
return dataKey["_id"].toString("base64")
}
}
Resulting Document
Package JSON MongoDB Driver/ MongoDB Client Side Encryption NPM Package Versions
"mongodb": "^3.6.0",
"mongodb-client-encryption": "^1.2.1"