Skip to content

Commit 65a57bd

Browse files
add documentation
1 parent 095c6c2 commit 65a57bd

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

docs/field-level-encryption.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,30 @@ const ModelWithBirthday = model.discriminator('ModelWithBirthday', new Schema({
216216
```
217217

218218
When generating encryption schemas, Mongoose merges all discriminators together for the all discriminators declared on the same namespace. As a result, discriminators that declare the same key with different types are not supported. Furthermore, all discriminators must share the same encryption type - it is not possible to configure discriminators on the same model for both CSFLE and QE.
219+
220+
## Managing Data Keys
221+
222+
Mongoose provides a convenient API to obtain a [ClientEncryption](https://mongodb.github.io/node-mongodb-native/Next/classes/ClientEncryption.html)
223+
object configured to manage data keys in the key vault. A client encryption can be obtained with the `Model.clientEncryption()` helper:
224+
225+
```javascript
226+
const connection = createConnection();
227+
228+
const schema = new Schema({
229+
name: {
230+
type: String, encrypt: { keyId }
231+
}
232+
}, {
233+
encryptionType: 'queryableEncryption'
234+
});
235+
236+
const Model = connection.model('BaseUserModel', schema);
237+
await connection.openUri(`mongodb://localhost:27017`, {
238+
autoEncryption: {
239+
keyVaultNamespace: 'datakeys.datakeys',
240+
kmsProviders: { local: '....' }
241+
}
242+
});
243+
244+
const clientEncryption = Model.clientEncryption();
245+
```

0 commit comments

Comments
 (0)