@@ -103,9 +103,10 @@ ref: create-a-data-encryption-key
103
103
level : 4
104
104
content : |
105
105
Construct a client with the MongoDB connection string and key vault
106
- namespace configuration, and create a data encryption key with the
107
- following **code snippet**. The key vault in
108
- this example uses the ``encryption`` database and ``__keyVault`` collection.
106
+ namespace configuration, create a unique index on the ``keyAltNames`` field
107
+ in that collection, and create a data encryption key with the following
108
+ **code snippet**. The key vault in this example uses the ``encryption``
109
+ database and ``__keyVault`` collection.
109
110
110
111
.. tabs-drivers::
111
112
@@ -298,7 +299,10 @@ content: |
298
299
:tabid: nodejs
299
300
300
301
.. code-block:: javascript
301
- :emphasize-lines: 4
302
+ :emphasize-lines: 7
303
+
304
+ const mongodb = require("mongodb")
305
+ const { MongoClient, Binary } = mongodb
302
306
303
307
const connectionString = 'mongodb://localhost:27017/';
304
308
const keyVaultDb = 'encryption';
@@ -316,7 +320,7 @@ content: |
316
320
const keyDB = client.db(keyVaultDb);
317
321
const keyColl = keyDB.collection(keyVaultCollection);
318
322
const query = {
319
- _id: base64KeyId,
323
+ _id: new Binary(Buffer.from( base64KeyId, "base64"), 4) ,
320
324
};
321
325
const dataKey = await keyColl.findOne(query);
322
326
console.log(dataKey);
0 commit comments