{"id":46282,"date":"2026-08-10T15:47:55","date_gmt":"2026-08-10T13:47:55","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/?p=46282"},"modified":"2026-08-10T15:47:58","modified_gmt":"2026-08-10T13:47:58","slug":"sql-server-vs-mongodb-when-the-cloud-is-your-adversary-always-encrypted-vs-queryable-encryption","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/sql-server-vs-mongodb-when-the-cloud-is-your-adversary-always-encrypted-vs-queryable-encryption\/","title":{"rendered":"SQL Server vs MongoDB: When the cloud is your adversary (Always Encrypted vs Queryable Encryption)"},"content":{"rendered":"\n<h2 id=\"h-the-real-barrier-to-the-cloud\" class=\"wp-block-heading\">The real barrier to the cloud<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When a company still refuses to put its sensitive data in the cloud, the reason usually isn&#8217;t cost or performance: it&#8217;s <strong>data sovereignty<\/strong>. In the cloud, someone else is the administrator of the machine; therefore the provider can, in theory, read the data files, see the data being used in memory, or read the backups. The threat model is no longer the external attacker but the privileged insider hosting the database.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As covered previously on my blog <em><a href=\"https:\/\/www.dbi-services.com\/blog\/tde-tls-data-security-governance-gap-in-lower-environments\/\">Beyond TDE and TLS: Bridging the Data Security Governance Gap in Lower Environments<\/a><\/em>, various encryption methods can protect you. For example, TLS protects data <em>in transit<\/em> and TDE protects it <em>at rest<\/em>, but as soon as the engine runs a query, it handles plaintext in memory. So there are three states to protect: <em>at-rest<\/em>, <em>in-transit<\/em>, <em>in-use<\/em>. The gap this article focuses on is the last one.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That is exactly what <a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/relational-databases\/security\/encryption\/always-encrypted-database-engine?view=sql-server-ver17\">Always Encrypted<\/a> (SQL Server) and <a href=\"https:\/\/www.mongodb.com\/docs\/manual\/core\/queryable-encryption\/?msockid=17bb9dfe67e76329082e8b4866e962fe\">Queryable Encryption<\/a> (MongoDB) target. The common principle: encryption and decryption happen client-side, in the driver; the keys never reach the engine. The data stays encrypted at rest, in transit, <strong>and<\/strong> during processing. The DBA, the cloud operator, the hypervisor admin: all of them see only cyphertext.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That leaves one question: if the engine sees only cyphertext, how does it answer a <code>WHERE<\/code> condition? Both database engines do answer it, but through different technical means.<\/p>\n\n\n\n<h2 id=\"h-sql-server-queryability-lives-in-the-cyphertext\" class=\"wp-block-heading\">SQL Server: queryability lives in the cyphertext<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To demonstrate all this, let&#8217;s start by creating a table with two columns, Salary and Department, encrypted deterministically on one side and randomized on the other:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nDROP TABLE IF EXISTS dbo.Employees;\nCREATE TABLE dbo.Employees (\n  Id         INT IDENTITY(1,1) PRIMARY KEY,\n  LastName   NVARCHAR(50) COLLATE Latin1_General_BIN2 NOT NULL,\n  FirstName  NVARCHAR(50) COLLATE Latin1_General_BIN2 NOT NULL,\n  DeptDet    NVARCHAR(30) COLLATE Latin1_General_BIN2 NOT NULL, -- will be DETERMINISTIC\n  DeptRand   NVARCHAR(30) COLLATE Latin1_General_BIN2 NOT NULL, -- will be RANDOMIZED\n  SalaryDet  INT NOT NULL, -- will be DETERMINISTIC\n  SalaryRand INT NOT NULL  -- will be RANDOMIZED\n);\nGO\n\nINSERT INTO dbo.Employees (LastName, FirstName, DeptDet, DeptRand, SalaryDet, SalaryRand) VALUES\n(&#039;Martin&#039;,  &#039;Alice&#039;, &#039;Sales&#039;, &#039;Sales&#039;, 55000, 55000),\n(&#039;Dubois&#039;,  &#039;Bob&#039;,   &#039;Sales&#039;, &#039;Sales&#039;, 48000, 48000),\n(&#039;Bernard&#039;, &#039;Chloe&#039;, &#039;Sales&#039;, &#039;Sales&#039;, 52000, 52000),\n(&#039;Petit&#039;,   &#039;David&#039;, &#039;IT&#039;,    &#039;IT&#039;,    72000, 72000),\n(&#039;Durand&#039;,  &#039;Emma&#039;,  &#039;IT&#039;,    &#039;IT&#039;,    68000, 68000);\n\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Five rows: three <code>Sales<\/code>, two <code>IT<\/code>. The <code>BIN2<\/code> collation is required by Always Encrypted (<a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/relational-databases\/security\/encryption\/always-encrypted-database-engine?view=sql-server-ver17\">link to documentation<\/a>), and the master key lives outside the database (Key Vault, certificate store, or HSM).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Column encryption isn&#8217;t done in T-SQL, because the engine doesn&#8217;t have the keys. It&#8217;s driven from the client (here in PowerShell), declaring for each value a deterministic column and its randomized twin:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\nImport-Module SqlServer -MinimumVersion 22.0.59\n$sqlConnectionString = &quot;Data Source=.\\LAB2025;Initial Catalog=AEDEMO;Integrated Security=True;Encrypt=False;Trust Server Certificate=False&quot;\n$smoDatabase = Get-SqlDatabase -ConnectionString $sqlConnectionString\n\n$encryptionChanges  = @()\n$encryptionChanges += New-SqlColumnEncryptionSettings -ColumnName dbo.Employees.DeptDet    -EncryptionType Deterministic -EncryptionKey &quot;CEK1&quot;\n$encryptionChanges += New-SqlColumnEncryptionSettings -ColumnName dbo.Employees.DeptRand   -EncryptionType Randomized    -EncryptionKey &quot;CEK1&quot;\n$encryptionChanges += New-SqlColumnEncryptionSettings -ColumnName dbo.Employees.SalaryDet  -EncryptionType Deterministic -EncryptionKey &quot;CEK1&quot;\n$encryptionChanges += New-SqlColumnEncryptionSettings -ColumnName dbo.Employees.SalaryRand -EncryptionType Randomized    -EncryptionKey &quot;CEK1&quot;\n\nSet-SqlColumnEncryption -ColumnEncryptionSettings $encryptionChanges -InputObject $smoDatabase\n\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">In this example, I&#8217;m working on my 2025 SQL Server instance, on the AEDEMO database, using the column encryption key <code>CEK1<\/code> I created beforehand (itself protected by a column master key stored outside the database).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We check that the engine sees the right type per column:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSELECT c.name, c.encryption_type_desc\nFROM sys.columns c\nWHERE c.object_id = OBJECT_ID(&#039;dbo.Employees&#039;);\n\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"350\" height=\"251\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-32.png\" alt=\"\" class=\"wp-image-46293\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-32.png 350w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-32-300x215.png 300w\" sizes=\"auto, (max-width: 350px) 100vw, 350px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The deterministic mechanism works like this: <strong>same plaintext, same cyphertext<\/strong> (an injective function). On an Always Encrypted-enabled connection with <em>Parameterization for Always Encrypted<\/em> and parameters for the predicates (never literals), equality works:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nDECLARE @d NVARCHAR(30) = &#039;Sales&#039;;\nSELECT DeptDet AS Enc, COUNT(*) FROM dbo.Employees WHERE DeptDet = @d\nGROUP BY DeptDet;\n\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"274\" height=\"88\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-33.png\" alt=\"\" class=\"wp-image-46295\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The driver encrypts <code>@d<\/code> with the same key, the server finds the encrypted values that are identical to the parameter, and the result is correct.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You pay for it in three ways&#8230;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>First weakness: deterministic encryption can cause a data leak.<\/strong> You don&#8217;t need the keys to see it. Just connect <em>without<\/em> Always Encrypted and read the table: the encrypted columns come out as raw binary.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT FirstName, DeptDet, DeptRand FROM dbo.Employees;\n\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"171\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-35-1024x171.png\" alt=\"\" class=\"wp-image-46298\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-35-1024x171.png 1024w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-35-300x50.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-35-768x128.png 768w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-35.png 1164w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Look at the <code>DeptDet<\/code> column: Alice, Bob, and Chloe share <strong>exactly the same blob<\/strong>, and David and Emma share another. Two distinct values across five rows. The adversary doesn&#8217;t know what <code>0x012536\u2026<\/code> means, but reads the structure: two departments, one with three people, the other with two, and who goes with whom. The <code>DeptRand<\/code> column, on the other hand, shows five all-different blobs: nothing to read.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It&#8217;s harmless on five rows; it isn&#8217;t on a real table. On a low-cardinality column (region, sex, status), the distribution of blobs can be compared to a known distribution, and frequency analysis often reconstructs the plaintext. <a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/relational-databases\/security\/encryption\/always-encrypted-database-engine?view=sql-server-ver17\" data-type=\"link\" data-id=\"https:\/\/learn.microsoft.com\/en-us\/sql\/relational-databases\/security\/encryption\/always-encrypted-database-engine?view=sql-server-ver17\">Microsoft&#8217;s documentation<\/a> puts it bluntly: an unauthorized user can guess information by examining patterns, especially when the set of possible values is small.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Second weakness: randomized encryption blocks every query.<\/strong> With randomized encryption, the driver adds a fresh random value to each cell before encrypting, so the same input produces a different cyphertext every time. Therefore, the leak is gone <span style=\"text-decoration: underline\">but so is the query<\/span>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nDECLARE @d NVARCHAR(30) = &#039;Sales&#039;;\nSELECT DeptRand AS Enc, COUNT(*) FROM dbo.Employees WHERE DeptRand = @d\nGROUP BY DeptRand;  \n\n<\/pre><\/div>\n\n\n<p class=\"has-vivid-red-color has-text-color has-link-color wp-elements-fb3f4cf17fe4032b7fdd63edf105c5d1 wp-block-paragraph\"><em>Msg 33277, Level 16, State 2, Line 6<br>Encryption scheme mismatch for columns\/variables &#8216;DeptRand&#8217;, &#8216;@d&#8217;. The<br>encryption scheme for the columns\/variables is (encryption_type =<br>&#8216;RANDOMIZED&#8217;, \u2026) and the expression near line &#8216;6&#8217; expects it to be<br>DETERMINISTIC, or RANDOMIZED, a BIN2 collation for string data types,<br>and an enclave-enabled column encryption key, or PLAINTEXT.<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The server can no longer compare, since the same plaintext produces a different cyphertext on every row. We gained confidentiality and lost the query. It&#8217;s all or nothing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Third weakness: no range, even with deterministic.<\/strong> Byte equality says nothing about order:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nDECLARE @s INT = 55000;\nSELECT FirstName FROM dbo.Employees WHERE SalaryDet &amp;lt; @s;\n\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\"><code>WHERE SalaryDet &lt; @s<\/code> fails even though the column is deterministic. Sorting, <code>BETWEEN<\/code>, <code>LIKE<\/code>: out of reach for Always Encrypted alone.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The verdict is clear: bare Always Encrypted means equality, or nothing (=, IN, GROUP BY, and DISTINCT supported).<\/p>\n\n\n\n<h2 id=\"h-mongodb-queryability-lives-in-a-protocol\" class=\"wp-block-heading\">MongoDB: queryability lives in a protocol<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">MongoDB&#8217;s Queryable Encryption makes optimal use of randomized encryption. On the server side, everything is Randomized-encrypted, as <a href=\"https:\/\/www.mongodb.com\/docs\/manual\/core\/queryable-encryption\/?msockid=17bb9dfe67e76329082e8b4866e962fe\">the documentation explains<\/a>: <em>the server has no knowledge of the data it processes<\/em>. The <strong>encrypted view<\/strong> (a client connected without the keys) confirms it: even the three <code>Sales<\/code> employees come out with all-different <code>BinData<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"598\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-55-1024x598.png\" alt=\"\" class=\"wp-image-46327\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-55-1024x598.png 1024w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-55-300x175.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-55-768x448.png 768w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-55.png 1374w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">No frequency leak, unlike SQL Server&#8217;s deterministic encryption. With the keys, the same <code>find<\/code> returns the plaintext:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"970\" height=\"842\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-54.png\" alt=\"\" class=\"wp-image-46325\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-54.png 970w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-54-300x260.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-54-768x667.png 768w\" sizes=\"auto, (max-width: 970px) 100vw, 970px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The technical mechanism behind this lies in the collection&#8217;s declaration. Each encrypted field carries a <code>queryType<\/code>, its parameters, and a distinct key (<code>keyId<\/code>), one Data Encryption Key per field, which is mandatory:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"979\" height=\"762\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-56.png\" alt=\"\" class=\"wp-image-46328\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-56.png 979w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-56-300x234.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-56-768x598.png 768w\" sizes=\"auto, (max-width: 979px) 100vw, 979px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">And queries with equality tests, range, and even equality on a field declared as range all work:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"880\" height=\"362\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-59.png\" alt=\"\" class=\"wp-image-46331\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-59.png 880w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-59-300x123.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-59-768x316.png 768w\" sizes=\"auto, (max-width: 880px) 100vw, 880px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"874\" height=\"259\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-66.png\" alt=\"\" class=\"wp-image-46341\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-66.png 874w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-66-300x89.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-66-768x228.png 768w\" sizes=\"auto, (max-width: 874px) 100vw, 874px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"778\" height=\"145\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-67.png\" alt=\"\" class=\"wp-image-46342\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-67.png 778w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-67-300x56.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-67-768x143.png 768w\" sizes=\"auto, (max-width: 778px) 100vw, 778px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">On the server side, MongoDB then maintains encrypted index structures, and for each query the driver generates cryptographic <em>tokens<\/em> that the server checks against those structures without ever seeing the plaintext. This is a <em><a href=\"https:\/\/www.mongodb.com\/docs\/manual\/core\/queryable-encryption\/?msockid=17bb9dfe67e76329082e8b4866e962fe\">searchable encryption<\/a><\/em> scheme. Range is available in <strong>GA<\/strong>, with no special hardware.<\/p>\n\n\n\n<h2 id=\"h-the-real-difference-comes-down-to-one-thing-the-driver\" class=\"wp-block-heading\">The real difference comes down to one thing: the driver<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">On the SQL Server side, the driver&#8217;s work stays thin: it encrypts the parameters, rewrites the query, decrypts the results. Queryability itself is already carried by the cyphertext; the driver doesn&#8217;t have to handle it. On the MongoDB side, the driver carries the whole protocol: it generates the tokens checked against the encrypted indexes.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"572\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-68-1024x572.png\" alt=\"\" class=\"wp-image-46348\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-68-1024x572.png 1024w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-68-300x168.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-68-768x429.png 768w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-68.png 1392w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Once the collection is in place, <code>find({ department: \"Sales\" })<\/code> is written like a normal query and the driver handles the encryption on its own. Each encrypted field needs its own key (Data Encryption Key). The master key must be pinned, otherwise orphaned keys return an <code>HMAC validation failure<\/code> error. And the encryption API is only available from a client created as encrypted, so not from a standard Compass connection, for example.<\/p>\n\n\n\n<h2 id=\"h-summary\" class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th><\/th><th>Always Encrypted<\/th><th>Queryable Encryption<\/th><\/tr><\/thead><tbody><tr><td>Server-side encryption<\/td><td>deterministic <em>or<\/em> randomized<\/td><td>always randomized<\/td><\/tr><tr><td>Equality<\/td><td>yes (deterministic)<\/td><td>yes<\/td><\/tr><tr><td>Range \/ sort<\/td><td>no<\/td><td>yes (GA)<\/td><\/tr><tr><td>Frequency analysis attack<\/td><td>yes, with deterministic<\/td><td>no<\/td><\/tr><tr><td>Where the search happens<\/td><td>in the cyphertext<\/td><td>in the protocol<\/td><\/tr><tr><td>Driver weight<\/td><td>light<\/td><td>heavy<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 id=\"h-what-if-you-wanted-range-while-staying-on-sql-server\" class=\"wp-block-heading\">What if you wanted range while staying on SQL Server?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This is where <strong><a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/relational-databases\/security\/encryption\/always-encrypted-enclaves?view=sql-server-ver17\" data-type=\"link\" data-id=\"https:\/\/learn.microsoft.com\/en-us\/sql\/relational-databases\/security\/encryption\/always-encrypted-enclaves?view=sql-server-ver17\">secure enclaves<\/a><\/strong> come in. The engine delegates the computation to an enclave: a protected memory region where the data is decrypted and processed in the clear, out of reach, including from the machine&#8217;s administrator. This is what unlocks range, <code>LIKE<\/code>, sorting, and in-place encryption: inside the enclave the server no longer compares encrypted bytes, it works on the plaintext. This gain has a price. It requires compatible hardware or secure virtualization, an attestation service to deploy and maintain, and keys configured for the enclave, which noticeably increases architectural complexity compared with classic Always Encrypted.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But it also changes the <strong>nature of the trust<\/strong>. Queryable Encryption rests on a cryptographic guarantee: the server <em>cannot<\/em> read, it&#8217;s a mathematical property. Enclaves rest on a hardware guarantee: you trust the CPU, and its attestation, to isolate the protected region.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There remains a third path, often mentioned: homomorphic encryption (FHE), which computes directly on the cyphertext without ever decrypting it. Elegant on paper, but out of the game for database search: the computational cost is massive and response time collapses as the volume grows. So the practical choice really does play out between the two worlds described here.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When the cloud admin is the threat: how SQL Server and MongoDB let you query encrypted data, and what each approach costs.<\/p>\n","protected":false},"author":157,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":"","_members_access_role":[],"_members_access_error":""},"categories":[955,229,3788,1739,99],"tags":[135,677,51],"type_dbi":[],"class_list":["post-46282","post","type-post","status-publish","format-standard","hentry","category-cloud","category-database-administration-monitoring","category-mongodb","category-nosql","category-sql-server","tag-cloud","tag-nosql-mongodb","tag-sql-server"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v28.2 (Yoast SEO v28.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>SQL Server vs MongoDB: When the cloud is your adversary (Always Encrypted vs Queryable Encryption) - dbi Blog<\/title>\n<meta name=\"description\" content=\"When the cloud admin is the threat: how SQL Server and MongoDB let you query encrypted data, and what each approach costs.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dbi-services.com\/blog\/sql-server-vs-mongodb-when-the-cloud-is-your-adversary-always-encrypted-vs-queryable-encryption\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL Server vs MongoDB: When the cloud is your adversary (Always Encrypted vs Queryable Encryption)\" \/>\n<meta property=\"og:description\" content=\"When the cloud admin is the threat: how SQL Server and MongoDB let you query encrypted data, and what each approach costs.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/sql-server-vs-mongodb-when-the-cloud-is-your-adversary-always-encrypted-vs-queryable-encryption\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-10T13:47:55+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-08-10T13:47:58+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-32.png\" \/>\n\t<meta property=\"og:image:width\" content=\"350\" \/>\n\t<meta property=\"og:image:height\" content=\"251\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Louis Tochon\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Louis Tochon\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/sql-server-vs-mongodb-when-the-cloud-is-your-adversary-always-encrypted-vs-queryable-encryption\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/sql-server-vs-mongodb-when-the-cloud-is-your-adversary-always-encrypted-vs-queryable-encryption\\\/\"},\"author\":{\"name\":\"Louis Tochon\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/person\\\/e4195b0cb120295b3407a502c23e75b6\"},\"headline\":\"SQL Server vs MongoDB: When the cloud is your adversary (Always Encrypted vs Queryable Encryption)\",\"datePublished\":\"2026-08-10T13:47:55+00:00\",\"dateModified\":\"2026-08-10T13:47:58+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/sql-server-vs-mongodb-when-the-cloud-is-your-adversary-always-encrypted-vs-queryable-encryption\\\/\"},\"wordCount\":1326,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/sql-server-vs-mongodb-when-the-cloud-is-your-adversary-always-encrypted-vs-queryable-encryption\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2026\\\/08\\\/image-32.png\",\"keywords\":[\"Cloud\",\"NoSQL MongoDB\",\"SQL Server\"],\"articleSection\":[\"Cloud\",\"Database Administration &amp; Monitoring\",\"MongoDB\",\"NoSQL\",\"SQL Server\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/sql-server-vs-mongodb-when-the-cloud-is-your-adversary-always-encrypted-vs-queryable-encryption\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/sql-server-vs-mongodb-when-the-cloud-is-your-adversary-always-encrypted-vs-queryable-encryption\\\/\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/sql-server-vs-mongodb-when-the-cloud-is-your-adversary-always-encrypted-vs-queryable-encryption\\\/\",\"name\":\"SQL Server vs MongoDB: When the cloud is your adversary (Always Encrypted vs Queryable Encryption) - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/sql-server-vs-mongodb-when-the-cloud-is-your-adversary-always-encrypted-vs-queryable-encryption\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/sql-server-vs-mongodb-when-the-cloud-is-your-adversary-always-encrypted-vs-queryable-encryption\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2026\\\/08\\\/image-32.png\",\"datePublished\":\"2026-08-10T13:47:55+00:00\",\"dateModified\":\"2026-08-10T13:47:58+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/person\\\/e4195b0cb120295b3407a502c23e75b6\"},\"description\":\"When the cloud admin is the threat: how SQL Server and MongoDB let you query encrypted data, and what each approach costs.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/sql-server-vs-mongodb-when-the-cloud-is-your-adversary-always-encrypted-vs-queryable-encryption\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/sql-server-vs-mongodb-when-the-cloud-is-your-adversary-always-encrypted-vs-queryable-encryption\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/sql-server-vs-mongodb-when-the-cloud-is-your-adversary-always-encrypted-vs-queryable-encryption\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2026\\\/08\\\/image-32.png\",\"contentUrl\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2026\\\/08\\\/image-32.png\",\"width\":350,\"height\":251},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/sql-server-vs-mongodb-when-the-cloud-is-your-adversary-always-encrypted-vs-queryable-encryption\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL Server vs MongoDB: When the cloud is your adversary (Always Encrypted vs Queryable Encryption)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/\",\"name\":\"dbi Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/person\\\/e4195b0cb120295b3407a502c23e75b6\",\"name\":\"Louis Tochon\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/ce0ee48c64e763e6c4076e21c80729d15bc4493288aeb8695125c69082100e10?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/ce0ee48c64e763e6c4076e21c80729d15bc4493288aeb8695125c69082100e10?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/ce0ee48c64e763e6c4076e21c80729d15bc4493288aeb8695125c69082100e10?s=96&d=mm&r=g\",\"caption\":\"Louis Tochon\"},\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/author\\\/louistochon\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"SQL Server vs MongoDB: When the cloud is your adversary (Always Encrypted vs Queryable Encryption) - dbi Blog","description":"When the cloud admin is the threat: how SQL Server and MongoDB let you query encrypted data, and what each approach costs.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.dbi-services.com\/blog\/sql-server-vs-mongodb-when-the-cloud-is-your-adversary-always-encrypted-vs-queryable-encryption\/","og_locale":"en_US","og_type":"article","og_title":"SQL Server vs MongoDB: When the cloud is your adversary (Always Encrypted vs Queryable Encryption)","og_description":"When the cloud admin is the threat: how SQL Server and MongoDB let you query encrypted data, and what each approach costs.","og_url":"https:\/\/www.dbi-services.com\/blog\/sql-server-vs-mongodb-when-the-cloud-is-your-adversary-always-encrypted-vs-queryable-encryption\/","og_site_name":"dbi Blog","article_published_time":"2026-08-10T13:47:55+00:00","article_modified_time":"2026-08-10T13:47:58+00:00","og_image":[{"width":350,"height":251,"url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-32.png","type":"image\/png"}],"author":"Louis Tochon","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Louis Tochon","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/sql-server-vs-mongodb-when-the-cloud-is-your-adversary-always-encrypted-vs-queryable-encryption\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/sql-server-vs-mongodb-when-the-cloud-is-your-adversary-always-encrypted-vs-queryable-encryption\/"},"author":{"name":"Louis Tochon","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/e4195b0cb120295b3407a502c23e75b6"},"headline":"SQL Server vs MongoDB: When the cloud is your adversary (Always Encrypted vs Queryable Encryption)","datePublished":"2026-08-10T13:47:55+00:00","dateModified":"2026-08-10T13:47:58+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/sql-server-vs-mongodb-when-the-cloud-is-your-adversary-always-encrypted-vs-queryable-encryption\/"},"wordCount":1326,"commentCount":0,"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/sql-server-vs-mongodb-when-the-cloud-is-your-adversary-always-encrypted-vs-queryable-encryption\/#primaryimage"},"thumbnailUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-32.png","keywords":["Cloud","NoSQL MongoDB","SQL Server"],"articleSection":["Cloud","Database Administration &amp; Monitoring","MongoDB","NoSQL","SQL Server"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/sql-server-vs-mongodb-when-the-cloud-is-your-adversary-always-encrypted-vs-queryable-encryption\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/sql-server-vs-mongodb-when-the-cloud-is-your-adversary-always-encrypted-vs-queryable-encryption\/","url":"https:\/\/www.dbi-services.com\/blog\/sql-server-vs-mongodb-when-the-cloud-is-your-adversary-always-encrypted-vs-queryable-encryption\/","name":"SQL Server vs MongoDB: When the cloud is your adversary (Always Encrypted vs Queryable Encryption) - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/sql-server-vs-mongodb-when-the-cloud-is-your-adversary-always-encrypted-vs-queryable-encryption\/#primaryimage"},"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/sql-server-vs-mongodb-when-the-cloud-is-your-adversary-always-encrypted-vs-queryable-encryption\/#primaryimage"},"thumbnailUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-32.png","datePublished":"2026-08-10T13:47:55+00:00","dateModified":"2026-08-10T13:47:58+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/e4195b0cb120295b3407a502c23e75b6"},"description":"When the cloud admin is the threat: how SQL Server and MongoDB let you query encrypted data, and what each approach costs.","breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/sql-server-vs-mongodb-when-the-cloud-is-your-adversary-always-encrypted-vs-queryable-encryption\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/sql-server-vs-mongodb-when-the-cloud-is-your-adversary-always-encrypted-vs-queryable-encryption\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dbi-services.com\/blog\/sql-server-vs-mongodb-when-the-cloud-is-your-adversary-always-encrypted-vs-queryable-encryption\/#primaryimage","url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-32.png","contentUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2026\/08\/image-32.png","width":350,"height":251},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/sql-server-vs-mongodb-when-the-cloud-is-your-adversary-always-encrypted-vs-queryable-encryption\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"SQL Server vs MongoDB: When the cloud is your adversary (Always Encrypted vs Queryable Encryption)"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/e4195b0cb120295b3407a502c23e75b6","name":"Louis Tochon","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/ce0ee48c64e763e6c4076e21c80729d15bc4493288aeb8695125c69082100e10?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/ce0ee48c64e763e6c4076e21c80729d15bc4493288aeb8695125c69082100e10?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ce0ee48c64e763e6c4076e21c80729d15bc4493288aeb8695125c69082100e10?s=96&d=mm&r=g","caption":"Louis Tochon"},"url":"https:\/\/www.dbi-services.com\/blog\/author\/louistochon\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/46282","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/157"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=46282"}],"version-history":[{"count":34,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/46282\/revisions"}],"predecessor-version":[{"id":46373,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/46282\/revisions\/46373"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=46282"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=46282"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=46282"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=46282"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}