Overview
This guide shows you how to build an application that implements the MongoDB Queryable Encryption feature to automatically encrypt and decrypt document fields.
Select your driver language in the dropdown menu on the right to learn how to create an application that automatically encrypts and decrypts document fields.
Note
MongoDB Community Edition doesn't support Queryable Encryption with Automatic Encryption. You must use MongoDB Atlas or MongoDB Enterprise Advanced to implement this sample application.
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.
Before You Get Started
Warning
MongoDB 8.2 Known Issue
Version 8.2.0 of mongocryptd might not run on Windows.
This bug affects In-Use Encryption
with the MongoDB .NET/C# Driver and might affect other drivers based
on your mongocryptd spawn arguments.
To learn more about this issue and how to resolve it, see Known Issues in the MongoDB 8.2 Release Notes.
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.
Full Application Code
To see the complete code for the sample application, select your programming language in the language selector.
Procedure
Learn More
To view a tutorial on production-ready Queryable Encryption with a remote KMS, see Queryable Encryption Tutorials.
To learn how Queryable Encryption works, see Queryable Encryption Fundamentals.
To learn more about the topics mentioned in this guide, see the following links:
Learn more about Queryable Encryption components on the Reference page.
Learn how Customer Master Keys and Data Encryption Keys work on the Encryption Keys and Key Vaults page.
See how KMS Providers manage your Queryable Encryption keys on the KMS Providers page.