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
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,6 +46,7 @@ If you have a question about Mongoose (not a bug report) please post it to eithe
46
46
* execute `npm run test-tsd` to run the typescript tests
47
47
* execute `npm run ts-benchmark` to run the typescript benchmark "performance test" for a single time.
48
48
* execute `npm run ts-benchmark-watch` to run the typescript benchmark "performance test" while watching changes on types folder. Note: Make sure to commit all changes before executing this command.
49
+
* in order to run tests that require an cluster with encryption locally, run `npm run test-encryption`. Alternatively, you can start an encrypted cluster using the `scripts/configure-cluster-with-encryption.sh` file.
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.
153
+
154
+
### Registering Models
155
+
156
+
Encrypted schemas must be registered on a connection, not the Mongoose global:
0 commit comments