Docs 菜单
Docs 主页
/
MongoDB Manual
/ / / / / /

查询包含加密字段的文档

在此页面上

  • Overview
  • 开始之前
  • 步骤

本指南向您展示如何使用启用了 Queryable Encryption 的应用程序来检索具有加密字段的文档。

完成本指南中的步骤后,您应该能够使用应用程序查询加密字段中的数据,并以授权用户身份解密这些字段。

创建加密集合并插入文档,然后再继续。

1

下面的代码示例对加密字段执行查找查询,并打印解密后的数据:

const findResult = await encryptedCollection.findOne({
"patientRecord.ssn": "987-65-4320",
});
console.log(findResult);
var ssnFilter = Builders<Patient>.Filter.Eq("patientRecord.ssn", patient.PatientRecord.Ssn);
var findResult = await encryptedCollection.Find(ssnFilter).ToCursorAsync();
Console.WriteLine(findResult.FirstOrDefault().ToJson());
var findResult PatientDocument
err = coll.FindOne(
context.TODO(),
bson.M{"patientRecord.ssn": "987-65-4320"},
).Decode(&findResult)
Patient findResult = collection.find(
new BsonDocument()
.append("patientRecord.ssn", new BsonString("987-65-4320")))
.first();
System.out.println(findResult);
const findResult = await encryptedCollection.findOne({
"patientRecord.ssn": "987-65-4320",
});
console.log(findResult);
find_result = encrypted_collection.find_one({
"patientRecord.ssn": "987-65-4320"
})
print(find_result)

上述代码示例的输出应类似于以下内容:

{
"_id": {
"$oid": "648b384a722cb9b8392df76a"
},
"name": "Jon Doe",
"record": {
"ssn": "987-65-4320",
"billing": {
"type": "Visa",
"number": "4111111111111111"
}
},
"__safeContent__": [
{
"$binary": {
"base64": "L1NsYItk0Sg+oL66DBj6IYHbX7tveANQyrU2cvMzD9Y=",
"subType": "00"
}
}
]
}

警告

不要修改 __safeContent__ 字段

__safeContent__字段对于可查询加密至关重要。请勿修改此字段的内容。

后退

创建集合