For AI agents: a documentation index is available at https://www.mongodb.com/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
Docs Menu

Use Explicit Encryption

This guide shows you how to encrypt a document with explicit encryption and a MongoDB driver.

After completing this guide, you can configure a driver to encrypt fields in a document using explicit encryption. With this knowledge, you can create a client application that uses explicit encryption. with automatic decryption.

Important

Do Not Use this Sample Application In Production

Because the instructions in this tutorial include storing an encryption key in an insecure environment, you should not use an unmodified version of this application in production. Using this application in production risks unauthorized access to the encryption key or loss of the key needed to decrypt your data. The purpose of this tutorial is to demonstrate how to use Queryable Encryption without needing to set up a Key Management System.

You can use a Key Management System to securely store your encryption key in a production environment. A KMS is a remote service that securely stores and manages your encryption keys. To learn how to set up a Queryable Encryption enabled application that uses a KMS, see the Queryable Encryption Tutorials.

To complete and run the code in this guide, you need to set up your development environment as shown in the Install a Queryable Encryption Compatible Driver and Dependencies page.

To see the complete code for the sample application, select your programming language in the language selector.

To view a tutorial on using Queryable Encryption with a remote KMS, see Queryable Encryption Tutorials.

To learn how Queryable Encryption works, see Queryable Encryption with Explicit Encryption.

To learn more about the topics mentioned in this guide, see the following links: