This project demonstrates an example implementation of Queryable Encryption for the MongoDB Node.js driver. To learn more about Queryable Encryption, see the Queryable Encryption section in the Server manual.
To run this sample application, you first need to install the following dependencies:
- MongoDB Server version 7.0 or later
- Automatic Encryption Shared Library version 7.0 or later
- Node.js
- npm
For more information on installation requirements for {+qe+}, see Installation Requirements.
-
Copy the
env_template
file in the root of the project directory to a file named.env
. -
Replace the placeholder values in the
.env
file with your own credentials. -
Start a MongoDB replica set with three nodes.
Note: If you are using mtools, you can create a replica set by running the following command:
mlaunch init --replicaset --nodes 3
-
In a shell, navigate to the project root directory.
-
Run
npm install
to install the Node.js driver andmongodb-client-encryption
packages.Note:
mongodb-client-encryption
must be version 2.8.0 or later. For more information on compatible package versions, see the Driver Compatibility Table.When using Node.js driver version
6.0.0
or later,mongodb-client-encryption
must have the same major version number as the driver. -
In
queryable-encryption-tutorial.js
, replace the placeholder<Your KMS Provider Name>
with a valid KMS provider name. -
Run
node queryable-encryption-tutorial
to start the app. -
If successful, the application will print a document to the console.