Skip to content

Latest commit

 

History

History

node

Node.js Queryable Encryption Tutorial

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.

Install Dependencies

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.

Configure Your Environment

  1. Copy the env_template file in the root of the project directory to a file named .env.

  2. Replace the placeholder values in the .env file with your own credentials.

  3. 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

Run the App

  1. In a shell, navigate to the project root directory.

  2. Run npm install to install the Node.js driver and mongodb-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.

  3. In queryable-encryption-tutorial.js, replace the placeholder <Your KMS Provider Name> with a valid KMS provider name.

  4. Run node queryable-encryption-tutorial to start the app.

  5. If successful, the application will print a document to the console.