-
-
Save kevinAlbs/ef8c97ae77f9947ea254c845f75a5592 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Run this file with the legacy mongo shell to mongocryptd. Example: | |
mongo --port 27020 ./elemMatch-to-mongocryptd.js */ | |
var schema = | |
{ | |
encryptMetadata: { | |
"keyId": [UUID()] | |
}, | |
properties: { | |
name: { | |
encrypt: { | |
bsonType: 'string', | |
algorithm: 'AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic' | |
} | |
}, | |
motherName: { | |
encrypt: { | |
bsonType: 'string', | |
algorithm: 'AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic' | |
} | |
} | |
}, | |
'bsonType': 'object' | |
} | |
var cmd = { | |
"find": "coll", | |
"filter": { | |
"bars": { | |
"$elemMatch": { | |
"name": "SuperA" | |
} | |
} | |
}, | |
"jsonSchema": schema, | |
"isRemoteSchema": false | |
} | |
print("sending command to mongocryptd:") | |
printjson(cmd) | |
var got = db.runCommand(cmd); | |
print("got response from mongocryptd:") | |
printjson(got) | |
// "bars" is not an encrypted field. Do not expect "SuperA" to be encrypted. | |
assert(got.result.filter.bars.$elemMatch.name.$eq == "SuperA") | |
/* Sample output: | |
sending command to mongocryptd: | |
{ | |
"find" : "coll", | |
"filter" : { | |
"bars" : { | |
"$elemMatch" : { | |
"name" : "SuperA" | |
} | |
} | |
}, | |
"jsonSchema" : { | |
"encryptMetadata" : { | |
"keyId" : [ | |
UUID("841f6caf-bed1-44cc-b79e-5ec89aeaa386") | |
] | |
}, | |
"properties" : { | |
"name" : { | |
"encrypt" : { | |
"bsonType" : "string", | |
"algorithm" : "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic" | |
} | |
}, | |
"motherName" : { | |
"encrypt" : { | |
"bsonType" : "string", | |
"algorithm" : "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic" | |
} | |
} | |
}, | |
"bsonType" : "object" | |
}, | |
"isRemoteSchema" : false | |
} | |
got response from mongocryptd: | |
{ | |
"hasEncryptionPlaceholders" : true, | |
"schemaRequiresEncryption" : true, | |
"result" : { | |
"find" : "coll", | |
"filter" : { | |
"bars" : { | |
"$elemMatch" : { | |
"name" : { | |
"$eq" : BinData(6,"ADMAAAAQYQABAAAABWtpABAAAAAEhB9sr77RRMy3nl7ImuqjhgJ2AAcAAABTdXBlckEAAA==") | |
} | |
} | |
} | |
}, | |
"lsid" : { | |
"id" : UUID("46bc4bbe-7132-45b3-8a7e-0af1ea12b46e") | |
} | |
}, | |
"ok" : 1 | |
} | |
uncaught exception: Error: assert failed : | |
doassert@src/mongo/shell/assert.js:20:14 | |
assert@src/mongo/shell/assert.js:151:9 | |
@elemMatch-to-mongocryptd.js:48:1 | |
failed to load: elemMatch-to-mongocryptd.js | |
exiting with code -3 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment