Docs Menu
Docs Home
/
MongoDB マニュアル
/ / / / / /

暗号化されたフィールドを持つドキュメントのクエリ

項目一覧

  • 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"
}
}
]
}

警告

MongoDB_ENUS_JAJP フィールドを変更しないでください

__safeContent__フィールドは Queryable Encryption に必須です。 このフィールドの内容は変更しないでください。

戻る

コレクションを作成する