Queryable Encryption is a MongoDB client-side encryption capability that allows applications to run queries on encrypted fields while the server stores, indexes and processes only ciphertext and never sees the plaintext values or the keys. In database security, it addresses a gap left by encryption at rest and in transit: data must normally be decrypted in server memory to be searched, which exposes it to administrators, compromised hosts and memory dumps.
The feature is based on structured encryption research and became generally available in MongoDB 7.0 for equality queries, with range queries added as generally available in MongoDB 8.0. Encryption and decryption happen in the driver on the client, so the trust boundary moves from the database server to the application that holds the keys.
How Queryable Encryption processes a query
Queryable Encryption works by encrypting each sensitive value in the client and storing it alongside encrypted search tokens that the server can match without learning the underlying value. When the application issues a query, the driver derives a cryptographic token from the plaintext search term, sends only that token, and the server compares it with its encrypted index structures.
- The application defines an encrypted fields map that lists which fields are encrypted and which query types each field supports.
- On insert, the driver encrypts the value with a data encryption key and creates metadata tokens for the server-side encrypted index.
- On query, the driver converts the search value into a token and rewrites the query before it leaves the client.
- The server returns matching documents still encrypted, and the driver decrypts the results for the authorized application.
The server maintains internal metadata collections that support the encrypted index. Those collections grow with every write, so encrypted collections need periodic compaction to keep storage and query performance under control.
Keys and the trust model
Queryable Encryption uses envelope encryption: each field is protected by a data encryption key, and those keys are themselves encrypted by a customer master key held outside the database. The encrypted data keys live in a key vault collection, while the master key stays in an external key management service or hardware security module.
| Component | Where it lives | Role |
|---|---|---|
| Customer master key | External KMS or HSM | Encrypts and decrypts data keys |
| Data encryption key | Key vault collection, encrypted | Encrypts individual field values |
| Encrypted fields map | Collection configuration and client | Declares encrypted fields and query types |
| Metadata collections | Database server | Hold tokens for the encrypted index |
Supported key providers include AWS KMS, Azure Key Vault, Google Cloud KMS and any KMIP-compliant server, plus a local key file intended only for development. Because the server never receives the master key, a database administrator cannot read protected fields, which supports separation of duties and reduces the impact of a stolen backup.
Supported query types and limits
Queryable Encryption supports a deliberately narrow set of operations, because each additional operation would leak more information to the server. Each encrypted field is configured for one query type when the collection is created, and that choice cannot be changed without migrating the data.
| Query type | Status | Typical use | Main constraint |
|---|---|---|---|
| Equality | Generally available since 7.0 | Lookup by national ID or account number | Exact match only |
| Range | Generally available since 8.0 | Salary bands, birth dates, amounts | Bounds and precision set in advance |
| Prefix, suffix, substring | Preview in recent releases | Partial name or code search | Not suited to production workloads yet |
| Unindexed encrypted field | Supported | Data never used in filters | Cannot be queried at all |
Operations such as sorting, arbitrary aggregation and regular expressions on encrypted values are not available. Applications that need them must decrypt results on the client and process them there, which shifts work and memory use to the application tier.
Queryable Encryption compared with other database encryption
The value of Queryable Encryption is clearest next to other encryption controls, each of which protects against a different threat. Transparent data encryption protects files on disk, while client-side approaches protect data from the database server itself.
| Approach | Server sees plaintext | Query on encrypted data | Main protection |
|---|---|---|---|
| Transparent data encryption | Yes, in memory | Yes, after decryption | Stolen disks and backups |
| Client-side field level encryption | No | Equality only with deterministic mode | Server and administrator access |
| Queryable Encryption | No | Equality and range, randomized | Server access and frequency analysis |
| Always Encrypted with secure enclaves | Only inside the enclave | Rich queries in the enclave | Administrator access outside the enclave |
The key difference from older client-side field level encryption is that Queryable Encryption uses randomized encryption: the same plaintext produces different ciphertexts, which defeats simple frequency analysis that deterministic encryption allows.
Costs, leakage and common mistakes
Queryable Encryption is not free of trade-offs, and teams should plan for storage growth, slower writes and some residual leakage. Encrypted index metadata can multiply storage per encrypted field several times, and range-indexed fields are the most expensive. The server can still observe access patterns, such as how often a token is queried and which documents match, so the scheme protects values rather than hiding all activity.
- Encrypting too many fields raises cost without benefit; reserve it for regulated or high-risk attributes.
- Choosing the wrong query type at creation forces a full data migration later.
- Storing the master key next to the database removes most of the protection.
- Skipping compaction lets metadata collections grow and slows queries over time.
- Losing the master key makes the encrypted data permanently unrecoverable.
The idea in brief
Queryable Encryption lets a database search through locked boxes without opening them. The application keeps the keys, puts sensitive values such as tax numbers or salaries into the locked boxes, and the database only ever stores the boxes.
When the application looks for a value, it sends a coded search slip instead of the value itself. The database matches slips to boxes and hands back the right ones, still locked. Only the application can open them, so even someone with full access to the database server sees nothing readable.
A practical scenario
A health insurer runs its claims platform on a managed MongoDB cluster operated by an external hosting provider. Regulators and internal policy require that hosting staff cannot read patient identifiers, yet call-center agents must look up members by insurance number and find claims within a billed amount range.
The engineering team encrypts the insurance number for equality queries and the claim amount for range queries, with the customer master key held in the insurer’s own cloud KMS. Diagnosis text is encrypted without indexing because it is never used in filters. After rollout, lookups by insurance number stay well within the agents’ response-time target, storage for the claims collection grows by roughly a third, and an audit confirms that a database snapshot given to the hosting provider contains no readable patient identifiers.