暗号化されたフィールドを持つドキュメントのクエリ
等価クエリを使用した Queryable Encryption は、MongoDB 7.0以降で通常使用可能(GA)です。 バージョン6.0でリリースされた Queryable Encryption Public Preview はサポートされなくなりました。 パブリック プレビューを使用して暗号化されたデータは、機能のリリースと互換性がありません。 詳細については、「 MongoDB 7.0の互換性の変更 」を参照してください。
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 に必須です。 このフィールドの内容は変更しないでください。