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
@@ -16,104 +16,6 @@ The resulting document will look similar to the following to a client that doesn
16
16
17
17
You can read more about CSFLE on the [MongoDB CSFLE documentation](https://www.mongodb.com/docs/manual/core/csfle/) and [this blog post about CSFLE in Node.js](https://www.mongodb.com/developer/languages/javascript/client-side-field-level-encryption-csfle-mongodb-node/).
18
18
19
-
Note that Mongoose does **not** currently have any Mongoose-specific APIs for CSFLE.
20
-
Mongoose defers all CSFLE-related work to the MongoDB Node.js driver, so the [`autoEncryption` option](https://mongodb.github.io/node-mongodb-native/5.6/interfaces/AutoEncryptionOptions.html) for `mongoose.connect()` and `mongoose.createConnection()` is where you put all CSFLE-related configuration.
21
-
Mongoose schemas currently don't support CSFLE configuration.
22
-
23
-
## Setting Up Field Level Encryption with Mongoose
24
-
25
-
First, you need to install the [mongodb-client-encryption npm package](https://www.npmjs.com/package/mongodb-client-encryption).
26
-
This is MongoDB's official package for setting up encryption keys.
27
-
28
-
```sh
29
-
npm install mongodb-client-encryption
30
-
```
31
-
32
-
You also need to make sure you've installed [mongocryptd](https://www.mongodb.com/docs/manual/core/queryable-encryption/reference/mongocryptd/).
33
-
mongocryptd is a separate process from the MongoDB server that you need to run to work with field level encryption.
34
-
You can either run mongocryptd yourself, or make sure it is on the system PATH and the MongoDB Node.js driver will run it for you.
35
-
[You can read more about mongocryptd here](https://www.mongodb.com/docs/v5.0/reference/security-client-side-encryption-appendix/#mongocryptd).
36
-
37
-
Once you've set up and run mongocryptd, first you need to create a new encryption key as follows.
38
-
Keep in mind that the following example is a simple example to help you get started.
39
-
The encryption key in the following example is insecure; MongoDB recommends using a [KMS](https://www.mongodb.com/docs/v5.0/core/security-client-side-encryption-key-management/).
40
-
41
-
```javascript
42
-
const { ClientEncryption } =require('mongodb');
43
-
constmongoose=require('mongoose');
44
-
45
-
run().catch(err=>console.log(err));
46
-
47
-
asyncfunctionrun() {
48
-
/* Step 1: Connect to MongoDB and insert a key */
49
-
50
-
// Create a very basic key. You're responsible for making
Once you have an encryption key, you can create a separate Mongoose connection with a [`schemaMap`](https://mongodb.github.io/node-mongodb-native/5.6/interfaces/AutoEncryptionOptions.html#schemaMap) that defines which fields are encrypted using JSON schema syntax as follows.
80
-
81
-
```javascript
82
-
/* Step 2: connect using schema map and new key */
With the above connection, if you create a model named 'Test' that uses the 'tests' collection, any documents will have their `name` property encrypted.
109
-
110
-
```javascript
111
-
// 'super secret' will be stored as 'BinData' in the database,
CSFLE/QE in Mongoose work by generating the encryption schema that the MongoDB driver expects for each encrypted model on the connection. This happens automatically when the model's connection is established.
73
+
Field level encryption in Mongoose works by generating the encryption schema that the MongoDB driver expects for each encrypted model on the connection. This happens automatically when the model's connection is established.
168
74
169
-
Queryable encryption and CSFLE requires all the same configuration as outlined in the [MongoDB encryption in-use documentation](https://www.mongodb.com/docs/manual/core/security-in-use-encryption/), except for the schemaMap or encryptedFieldsMap options.
75
+
Queryable encryption and CSFLE require all the same configuration as outlined in the [MongoDB encryption in-use documentation](https://www.mongodb.com/docs/manual/core/security-in-use-encryption/), except for the schemaMap or encryptedFieldsMap options.
170
76
171
77
```javascript
172
78
constkeyVaultNamespace='client.encryption';
@@ -215,7 +121,7 @@ const ModelWithBirthday = model.discriminator('ModelWithBirthday', new Schema({
215
121
}));
216
122
```
217
123
218
-
When generating encryption schemas, Mongoose merges all discriminators together for all of the 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.
124
+
When generating encryption schemas, Mongoose merges all discriminators together for all of the discriminators declared on the same namespace. As a result, discriminators that declare the same key with different types are not supported. Furthermore, all discriminators for the same namespace must share the same encryption type - it is not possible to configure discriminators on the same model for both CSFLE and Queryable Encryption.
First, you need to install the [mongodb-client-encryption npm package](https://www.npmjs.com/package/mongodb-client-encryption).
156
+
This is MongoDB's official package for setting up encryption keys.
157
+
158
+
```sh
159
+
npm install mongodb-client-encryption
160
+
```
161
+
162
+
You also need to make sure you've installed [mongocryptd](https://www.mongodb.com/docs/manual/core/queryable-encryption/reference/mongocryptd/).
163
+
mongocryptd is a separate process from the MongoDB server that you need to run to work with field level encryption.
164
+
You can either run mongocryptd yourself, or make sure it is on the system PATH and the MongoDB Node.js driver will run it for you.
165
+
[You can read more about mongocryptd here](https://www.mongodb.com/docs/v5.0/reference/security-client-side-encryption-appendix/#mongocryptd).
166
+
167
+
Once you've set up and run mongocryptd, first you need to create a new encryption key as follows.
168
+
Keep in mind that the following example is a simple example to help you get started.
169
+
The encryption key in the following example is insecure; MongoDB recommends using a [KMS](https://www.mongodb.com/docs/v5.0/core/security-client-side-encryption-key-management/).
170
+
171
+
```javascript
172
+
const { ClientEncryption } =require('mongodb');
173
+
constmongoose=require('mongoose');
174
+
175
+
run().catch(err=>console.log(err));
176
+
177
+
asyncfunctionrun() {
178
+
/* Step 1: Connect to MongoDB and insert a key */
179
+
180
+
// Create a very basic key. You're responsible for making
Once you have an encryption key, you can create a separate Mongoose connection with a [`schemaMap`](https://mongodb.github.io/node-mongodb-native/5.6/interfaces/AutoEncryptionOptions.html#schemaMap) that defines which fields are encrypted using JSON schema syntax as follows.
210
+
211
+
```javascript
212
+
/* Step 2: connect using schema map and new key */
With the above connection, if you create a model named 'Test' that uses the 'tests' collection, any documents will have their `name` property encrypted.
239
+
240
+
```javascript
241
+
// 'super secret' will be stored as 'BinData' in the database,
0 commit comments