You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Mongoose supports the declaration of encrypted schemas - schemas that, when connected to a model, utilize MongoDB's Client Side
119
+
Field Level Encryption or Queryable Encryption under the hood. Mongoose automatically generates either an `encryptedFieldsMap` or a
120
+
`schemaMap` when instantiating a MongoClient and encrypts fields on write and decrypts fields on reads.
121
+
122
+
### Encryption types
123
+
124
+
MongoDB has to different automatic encryption implementations: client side field level encryption (CSFLE) and queryable encryption (QE).
125
+
See [choosing an in-use encryption approach](https://www.mongodb.com/docs/v7.3/core/queryable-encryption/about-qe-csfle/#choosing-an-in-use-encryption-approach).
126
+
127
+
### Declaring Encrypted Schemas
128
+
129
+
The following schema declares two properties, `name` and `ssn`. `ssn` is encrypted using queryable encryption, and
130
+
is configured for equality queries:
131
+
132
+
```javascript
133
+
constencryptedUserSchema=newSchema({
134
+
name:String,
135
+
ssn: {
136
+
type:String,
137
+
// 1
138
+
encrypt: {
139
+
keyId:'<uuid string of key id>',
140
+
queries:'equality'
141
+
}
142
+
}
143
+
// 2
144
+
}, { encryptionType:'queryable encryption' });
145
+
```
146
+
147
+
To declare a field as encrypted, you must:
148
+
149
+
1. Annotate the field with encryption metadata in the schema definition
150
+
2. Choose an encryption type for the schema and configure the schema for the encryption type
151
+
152
+
Not all schematypes are supported for CSFLE and QE. For an overview of valid schema types, refer to MongoDB's documentation.
0 commit comments