Overview
このガイドでは、Queryable Encryption 対応コレクションを作成し、暗号化されたフィールドを持つドキュメントを挿入する方法について説明します。
このガイドの手順を完了すると、暗号化されたコレクションを作成し、CMK で暗号化されたフィールドを含むドキュメントを挿入できるようになります。
始める前に
暗号化されたコレクションを作成する前に、Queryable Encryption 対応のアプリケーションを作成します。
明示的な暗号化を使用している場合は、暗号化されたフィールドごとに一意の データ暗号化キー も事前に作成する必要があります。 詳細については、「暗号化キーとキー ボールト 」を参照してください。
手順
暗号化するフィールドの指定
フィールドを暗号化するには、それを暗号化スキーマに追加します。フィールドでクエリを有効にするには、queries
プロパティを追加します。次のタイプのクエリでフィールドをクエリ可能にできます。
Equality(等価)
Range(範囲)
プレフィックス、サフィックス、またはサブストリング
次の手順は、各クエリ タイプで暗号化するフィールドを指定する方法を示しています。
等価クエリのフィールドを指定する
フィールドで等価クエリを有効にするには、
queryType
が"equality"
であるフィールドを暗号化スキーマに追加します。 次のコードサンプルはssn
billing
ssn
フィールドと フィールドの両方を暗号化しますが、クエリ可能なのは フィールドのみです。const encryptedFieldsMap = { encryptedFields: { fields: [ { path: "patientRecord.ssn", bsonType: "string", queries: { queryType: "equality" }, }, { path: "patientRecord.billing", bsonType: "object", }, ], }, }; var encryptedFields = new BsonDocument { { "fields", new BsonArray { new BsonDocument { { "keyId", BsonNull.Value }, { "path", "patientRecord.ssn" }, { "bsonType", "string" }, { "queries", new BsonDocument("queryType", "equality") } }, new BsonDocument { { "keyId", BsonNull.Value }, { "path", "patientRecord.billing" }, { "bsonType", "object" } } } } }; encryptedFieldsMap := bson.M{ "fields": []bson.M{ bson.M{ "keyId": nil, "path": "patientRecord.ssn", "bsonType": "string", "queries": []bson.M{ { "queryType": "equality", }, }, }, bson.M{ "keyId": nil, "path": "patientRecord.billing", "bsonType": "object", }, }, } BsonDocument encryptedFieldsMap = new BsonDocument().append("fields", new BsonArray(Arrays.asList( new BsonDocument() .append("keyId", new BsonNull()) .append("path", new BsonString("patientRecord.ssn")) .append("bsonType", new BsonString("string")) .append("queries", new BsonDocument() .append("queryType", new BsonString("equality"))), new BsonDocument() .append("keyId", new BsonNull()) .append("path", new BsonString("patientRecord.billing")) .append("bsonType", new BsonString("object"))))); const encryptedFieldsMap = { encryptedFields: { fields: [ { path: "patientRecord.ssn", bsonType: "string", queries: { queryType: "equality" }, }, { path: "patientRecord.billing", bsonType: "object", }, ], }, }; $encryptedFieldsMap = [ 'encryptedFields' => [ 'fields' => [ [ 'path' => 'patientRecord.ssn', 'bsonType' => 'string', 'queries' => ['queryType' => 'equality'], 'keyId' => null, ], [ 'path' => 'patientRecord.billing', 'bsonType' => 'object', 'keyId' => null, ], ], ], ]; encrypted_fields_map = { "fields": [ { "path": "patientRecord.ssn", "bsonType": "string", "queries": [{"queryType": "equality"}] }, { "path": "patientRecord.billing", "bsonType": "object", } ] } let encrypted_fields_map = doc! { "fields": [ { "path": "patientRecord.ssn", "bsonType": "string", "keyId": Bson::Null, "queries": { "queryType": "equality" }, }, { "path": "patientRecord.billing", "bsonType": "object", "keyId": Bson::Null, }, ] }; 範囲クエリのフィールドを指定する
フィールドで範囲クエリを有効にするには、
queryType
が"range"
であるフィールドを暗号化スキーマに追加します。 次の例では、前のステップで作成された暗号化スキーマにbillAmount
フィールドを追加し、範囲クエリを有効にします。const encryptedFieldsMap = { encryptedFields: { fields: [ { path: "patientRecord.ssn", bsonType: "string", queries: { queryType: "equality" }, }, { path: "patientRecord.billing", bsonType: "object", }, { path: "patientRecord.billAmount", bsonType: "int", queries: { queryType: "range", sparsity: 1, trimFactor: 4, min: 100, max: 2000, }, }, ], }, }; var encryptedFields = new BsonDocument { { "fields", new BsonArray { new BsonDocument { { "keyId", BsonNull.Value }, { "path", "patientRecord.ssn" }, { "bsonType", "string" }, { "queries", new BsonDocument("queryType", "equality") } }, new BsonDocument { { "keyId", BsonNull.Value }, { "path", "patientRecord.billing" }, { "bsonType", "object" } }, new BsonDocument { { "keyId", BsonNull.Value }, { "path", "patientRecord.billAmount" }, { "bsonType", "int" }, { "queries", new BsonDocument { { "queryType", "range" }, { "sparsity", 1 }, { "min", 100 }, { "max", 2000 }, { "trimFactor", 4 } } }, } } } }; encryptedFieldsMap := bson.M{ "fields": []bson.M{ bson.M{ "keyId": nil, "path": "patientRecord.ssn", "bsonType": "string", "queries": []bson.M{ { "queryType": "equality", }, }, }, bson.M{ "keyId": nil, "path": "patientRecord.billing", "bsonType": "object", }, bson.M{ "keyId": nil, "path": "patientRecord.billAmount", "bsonType": "int", "queries": []bson.M{ { "queryType": "range", "sparsity": 1, "min": 100, "max": 2000, "trimFactor": 4, }, }, }, }, } BsonDocument encryptedFieldsMap = new BsonDocument().append("fields", new BsonArray(Arrays.asList( new BsonDocument() .append("keyId", new BsonNull()) .append("path", new BsonString("patientRecord.ssn")) .append("bsonType", new BsonString("string")) .append("queries", new BsonDocument() .append("queryType", new BsonString("equality"))), new BsonDocument() .append("keyId", new BsonNull()) .append("path", new BsonString("patientRecord.billing")) .append("bsonType", new BsonString("object")), new BsonDocument() .append("keyId", new BsonNull()) .append("path", new BsonString("patientRecord.billAmount")) .append("bsonType", new BsonString("int")) .append("queries", new BsonDocument() .append("queryType", new BsonString("range")) .append("sparsity", new BsonInt32(1)) .append("trimFactor", new BsonInt32(4)) .append("min", new BsonInt32(100)) .append("max", new BsonInt32(2000)) )))); const encryptedFieldsMap = { encryptedFields: { fields: [ { path: "patientRecord.ssn", bsonType: "string", queries: { queryType: "equality" }, }, { path: "patientRecord.billing", bsonType: "object", }, { path: "patientRecord.billAmount", bsonType: "int", queries: { queryType: "range", sparsity: 1, trimFactor: 4, min: 100, max: 2000, }, }, ], }, }; $encryptedFieldsMap = [ 'encryptedFields' => [ 'fields' => [ [ 'path' => 'patientRecord.ssn', 'bsonType' => 'string', 'queries' => ['queryType' => 'equality'], 'keyId' => null, ], [ 'path' => 'patientRecord.billing', 'bsonType' => 'object', 'keyId' => null, ], [ 'path' => 'patientRecord.billAmount', 'bsonType' => 'int', 'queries' => [ 'queryType' => 'range', 'sparsity' => 1, 'trimFactor' => 4, 'min' => 100, 'max' => 2000, ], 'keyId' => null, ], ], ], ]; encrypted_fields_map = { "fields": [ { "path": "patientRecord.ssn", "bsonType": "string", "queries": [{"queryType": "equality"}] }, { "path": "patientRecord.billing", "bsonType": "object", }, { "path": "patientRecord.billAmount", "bsonType": "int", "queries": [{ "queryType": "range", "sparsity": 1, "min": 100, "max": 2000, "trimFactor": 4 }], }, ] } let encrypted_fields_map = doc! { "fields": [ { "path": "patientRecord.ssn", "bsonType": "string", "keyId": Bson::Null, "queries": { "queryType": "equality" }, }, { "path": "patientRecord.billing", "bsonType": "object", "keyId": Bson::Null, }, { "path": "patientRecord.billAmount", "bsonType": "int", "queries": { "queryType": "range", "sparsity": 1, "min": 100, "max": 2000, "trimFactor": 4 }, }, ] }; プレフィックス、サフィックス、またはサブストリング クエリのフィールドを指定する
フィールドでプレフィックス、サフィックス、またはサブストリング クエリを有効にするには、
"prefixPreview"
、"suffixPreview"
、または"substringPreview"
と関連するオプションのqueryType
を使用してフィールドを暗号化スキーマに追加します。次の例では、patientRecord.ssn
フィールドでプレフィックス クエリを有効にします。var encryptedFields = new BsonDocument { { "fields", new BsonArray { new BsonDocument { { "keyId", BsonNull.Value }, { "path", "patientRecord.ssn" }, { "bsonType", "string" }, { "queries", new BsonDocument { { "queryType", "prefixPreview" }, { "strMinQueryLength", 3 }, { "strMaxQueryLength", 10 }, { "caseSensitive", true }, { "diacriticSensitive", true } } } } } } }; Tip
サフィックス クエリ
フィールドでサフィックス クエリを有効にするには、前述のコード例で
queryType
オプションを"suffixPreview"
に変更します。次の例では、
patientRecord.ssn
フィールドで部分文字列クエリを有効にします。var encryptedFields = new BsonDocument { { "fields", new BsonArray { new BsonDocument { { "keyId", BsonNull.Value }, { "path", "patientRecord.ssn" }, { "bsonType", "string" }, { "queries", new BsonDocument { { "queryType", "substringPreview" }, { "strMaxLength", 12 }, { "strMinQueryLength", 3 }, { "strMaxQueryLength", 10 }, { "caseSensitive", true }, { "diacriticSensitive", true } } } } } } }; BsonDocument encryptedFieldsMap = new BsonDocument().append("fields", new BsonArray(Arrays.asList( new BsonDocument() .append("keyId", new BsonNull()) .append("path", new BsonString("patientRecord.ssn")) .append("bsonType", new BsonString("string")) .append("queries", new BsonDocument() .append("queryType", new BsonString("prefixPreview")) .append("strMinQueryLength", new BsonInt32(3)) .append("strMaxQueryLength", new BsonInt32(10)) .append("caseSensitive", new BsonBoolean(true)) .append("diacriticSensitive", new BsonBoolean(true)))))); Tip
サフィックス クエリ
フィールドでサフィックス クエリを有効にするには、前述のコード例で
queryType
オプションを"suffixPreview"
に変更します。次の例では、
patientRecord.ssn
フィールドで部分文字列クエリを有効にします。BsonDocument encryptedFieldsMap = new BsonDocument().append("fields", new BsonArray(Arrays.asList( new BsonDocument() .append("keyId", new BsonNull()) .append("path", new BsonString("patientRecord.ssn")) .append("bsonType", new BsonString("string")) .append("queries", new BsonDocument() .append("queryType", new BsonString("substringPreview")) .append("strMaxLength", new BsonInt32(12)) .append("strMinQueryLength", new BsonInt32(3)) .append("strMaxQueryLength", new BsonInt32(10)) .append("caseSensitive", new BsonBoolean(true)) .append("diacriticSensitive", new BsonBoolean(true)))))); const encryptedFieldsMap = { encryptedFields: { fields: [ { keyId: dek, path: "patientRecord.ssn", bsonType: "string", queries: { queryType: "prefixPreview", strMinQueryLength: 3, strMaxQueryLength: 10, caseSensitive: true, diacriticSensitive: true, }, }, ], }, }; Tip
サフィックス クエリ
フィールドでサフィックス クエリを有効にするには、前述のコード例で
queryType
オプションを"suffix"
に変更します。次の例では、
patientRecord.ssn
フィールドで部分文字列クエリを有効にします。const encryptedFieldsMap = { encryptedFields: { fields: [ { keyId: dek, path: "patientRecord.ssn", bsonType: "string", queries: { queryType: "substringPreview", strMaxLength: 12, strMinQueryLength: 3, strMaxQueryLength: 10, caseSensitive: true, diacriticSensitive: true, }, }, ], }, }; encrypted_fields_map = { "fields": [ { "path": "patientRecord.ssn", "bsonType": "string", "queries": [{ "queryType": "prefixPreview", "strMinQueryLength": 3, "strMaxQueryLength": 10, "caseSensitive": True, "diacriticSensitive": True, }] }, ] } Tip
サフィックス クエリ
フィールドでサフィックス クエリを有効にするには、前述のコード例で
queryType
オプションを"suffixPreview"
に変更します。次の例では、
patientRecord.ssn
フィールドで部分文字列クエリを有効にします。encrypted_fields_map = { "fields": [ { "path": "patientRecord.ssn", "bsonType": "string", "queries": [{ "queryType": "substringPreview", "strMaxLength": 12, "strMinQueryLength": 3, "strMaxQueryLength": 10, "caseSensitive": True, "diacriticSensitive": True, }] }, ] }
これらのステップの拡張バージョンについては、「暗号化スキーマの作成 」を参照してください。
暗号化ヘルパーメソッドのAPIにアクセスするためにクライアント暗号化オブジェクトをインスタンス化します
const clientEncryption = encryptedClient.getClientEncryption();
var clientEncryptionOptions = new ClientEncryptionOptions( keyVaultClient: keyVaultClient, keyVaultNamespace: keyVaultNamespace, kmsProviders: kmsProviderCredentials ); var clientEncryption = new ClientEncryption(clientEncryptionOptions);
opts := options.ClientEncryption(). SetKeyVaultNamespace(keyVaultNamespace). SetKmsProviders(kmsProviderCredentials) clientEncryption, err := mongo.NewClientEncryption(encryptedClient, opts) if err != nil { panic(fmt.Sprintf("Unable to create a ClientEncryption instance due to the following error: %s\n", err)) }
ClientEncryptionSettings clientEncryptionSettings = ClientEncryptionSettings.builder() .keyVaultMongoClientSettings(MongoClientSettings.builder() .applyConnectionString(new ConnectionString(uri)) .build()) .keyVaultNamespace(keyVaultNamespace) .kmsProviders(kmsProviderCredentials) .build(); ClientEncryption clientEncryption = ClientEncryptions.create(clientEncryptionSettings);
const clientEncryption = new ClientEncryption( encryptedClient, autoEncryptionOptions );
$clientEncryption = $encryptedClient->createClientEncryption($autoEncryptionOptions);
client_encryption = ClientEncryption( kms_providers=kms_provider_credentials, key_vault_namespace=key_vault_namespace, key_vault_client=encrypted_client, codec_options=CodecOptions(uuid_representation=STANDARD) )
let encrypted_client = encrypted_client_builder .extra_options(Some(doc!{ "cryptSharedLibPath": env::var("SHARED_LIB_PATH").expect("Set SHARED_LIB_PATH environment variable to path to crypt_shared library") })) .key_vault_client(Client::with_uri_str(uri).await.unwrap()) .build() .await .unwrap();
コレクションの作成
重要
挿入操作で暗黙的にコレクションを作成するのではなく、明示的にコレクションを作成します。 createCollection()
を使用してコレクションを作成すると、MongoDB は暗号化されたフィールドにインデックスを作成します。 このインデックスがないと、暗号化されたフィールドに対するクエリの実行が遅くなる可能性があります。
ClientEncryption
クラスからアクセスされる暗号化ヘルパー メソッドを使用して、暗号化されたコレクションを作成します。 このメソッドは、暗号化されたフィールドのデータ暗号化キーを自動的に生成し、暗号化されたコレクションを作成します。
await clientEncryption.createEncryptedCollection( encryptedDatabaseName, encryptedCollectionName, { provider: kmsProviderName, createCollectionOptions: encryptedFieldsMap, masterKey: customerMasterKeyCredentials, } );
このチュートリアルの C# バージョンでは、ドキュメント構造を表すためのデータモデルとして個別の クラスを使用します。 次のPatient
、 PatientRecord
、 PatientBilling
クラスをプロジェクトに追加します。
using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; [ ]public class Patient { public ObjectId Id { get; set; } public string PatientName { get; set; } public PatientRecord PatientRecord { get; set; } }
public class PatientRecord { public string Ssn { get; set; } public PatientBilling Billing { get; set; } public int BillAmount { get; set; } }
public class PatientBilling { public string CardType { get; set; } public long CardNumber { get; set; } }
これらのクラスを追加したら、 ClientEncryption
クラスからアクセスされる暗号化ヘルパー メソッドを使用して暗号化されたコレクションを作成します。 このメソッドは、暗号化されたフィールドのデータ暗号化キーを自動的に生成し、暗号化されたコレクションを作成します。
var createCollectionOptions = new CreateCollectionOptions<Patient> { EncryptedFields = encryptedFields }; clientEncryption.CreateEncryptedCollection(patientDatabase, encryptedCollectionName, createCollectionOptions, kmsProviderName, customerMasterKeyCredentials);
Tip
データベースとデータベース名
コレクションを作成するメソッドには、データベース名ではなく、データベースオブジェクトへの参照が必要です。
このチュートリアルのGoバージョンでは、データモデルを使用してドキュメント構造を表します。 コレクション内のデータを表すには、次の構造体をプロジェクトに追加します。
type PatientDocument struct { PatientName string `bson:"patientName"` PatientID int32 `bson:"patientId"` PatientRecord PatientRecord `bson:"patientRecord"` }
type PatientRecord struct { SSN string `bson:"ssn"` Billing PaymentInfo `bson:"billing"` BillAmount int `bson:"billAmount"` }
type PaymentInfo struct { Type string `bson:"type"` Number string `bson:"number"` }
これらのクラスを追加したら、 ClientEncryption
クラスからアクセスされる暗号化ヘルパー メソッドを使用して暗号化されたコレクションを作成します。 このメソッドは、暗号化されたフィールドのデータ暗号化キーを自動的に生成し、暗号化されたコレクションを作成します。
createCollectionOptions := options.CreateCollection().SetEncryptedFields(encryptedFieldsMap) _, _, err = clientEncryption.CreateEncryptedCollection( context.TODO(), encryptedClient.Database(encryptedDatabaseName), encryptedCollectionName, createCollectionOptions, kmsProviderName, customerMasterKey, )
Tip
データベースとデータベース名
暗号化されたコレクションを作成するメソッドには、データベース名ではなく 、データベースオブジェクトへの参照が必要です。 この参照は、クライアント オブジェクトで メソッドを使用して取得できます。
ClientEncryption
クラスからアクセスされる暗号化ヘルパー メソッドを使用して、暗号化されたコレクションを作成します。 このメソッドは、暗号化されたフィールドのデータ暗号化キーを自動的に生成し、暗号化されたコレクションを作成します。
CreateCollectionOptions createCollectionOptions = new CreateCollectionOptions().encryptedFields(encryptedFieldsMap); CreateEncryptedCollectionParams encryptedCollectionParams = new CreateEncryptedCollectionParams(kmsProviderName); encryptedCollectionParams.masterKey(customerMasterKeyCredentials); try { clientEncryption.createEncryptedCollection( encryptedClient.getDatabase(encryptedDatabaseName), encryptedCollectionName, createCollectionOptions, encryptedCollectionParams); }
Tip
データベースとデータベース名
暗号化されたコレクションを作成するメソッドには、データベース名ではなく 、データベースオブジェクトへの参照が必要です。 この参照は、クライアント オブジェクトで メソッドを使用して取得できます。
注意
Import ClientEncryption
Node.js ドライバー v6.0 以降を使用する場合は、 mongodb
ClientEncryption
をインポートする必要があります。
以前のドライバー バージョンの場合は、 mongodb-client-encryption
ClientEncryption
をインポートします。
ClientEncryption
クラスからアクセスされる暗号化ヘルパー メソッドを使用して、暗号化されたコレクションを作成します。 このメソッドは、暗号化されたフィールドのデータ暗号化キーを自動的に生成し、暗号化されたコレクションを作成します。
await clientEncryption.createEncryptedCollection( encryptedDatabase, encryptedCollectionName, { provider: kmsProviderName, createCollectionOptions: encryptedFieldsMap, masterKey: customerMasterKeyCredentials, } );
Tip
データベースとデータベース名
暗号化されたコレクションを作成するメソッドには、データベース名ではなく 、データベースオブジェクトへの参照が必要です。
暗号化されたコレクションを作成するには、データベースで createEncryptedCollection()
メソッドを呼び出します。このメソッドは、暗号化されたフィールドのデータ暗号化キーを自動的に生成し、 暗号化されたコレクションを作成します。
$client->getDatabase($encryptedDatabase)->createEncryptedCollection( $encryptedCollectionName, $clientEncryption, $kmsProviderName, $customerMasterKeyCredentials, $encryptedFieldsMap, );
ClientEncryption
クラスからアクセスされる暗号化ヘルパー メソッドを使用して、暗号化されたコレクションを作成します。 このメソッドは、暗号化されたフィールドのデータ暗号化キーを自動的に生成し、暗号化されたコレクションを作成します。
client_encryption.create_encrypted_collection( encrypted_client[encrypted_database_name], encrypted_collection_name, encrypted_fields_map, kms_provider_name, customer_master_key_credentials, )
Tip
データベースとデータベース名
暗号化されたコレクションを作成するメソッドには、データベース名ではなく 、データベースオブジェクトへの参照が必要です。 この参照は、クライアント オブジェクトで メソッドを使用して取得できます。
ClientEncryption
クラスからアクセスされる暗号化ヘルパー メソッドを使用して、暗号化されたコレクションを作成します。 このメソッドは、暗号化されたフィールドのデータ暗号化キーを自動的に生成し、暗号化されたコレクションを作成します。
client_encryption.create_encrypted_collection( &encrypted_client.database(encrypted_database_name), encrypted_collection_name, customer_master_key_credentials ) .encrypted_fields(encrypted_fields_map) .await .1?;
Tip
データベースとデータベース名
暗号化されたコレクションを作成するメソッドには、データベース名ではなく、データベースオブジェクトへの参照が必要です。この参照は、クライアントオブジェクトで database()
メソッドを使用して取得できます。
暗号化されたフィールドを持つドキュメントの挿入
ユーザの個人情報を説明するサンプルドキュメントを作成します。 次の例に示すように、暗号化されたクライアントを使用して、 patients
コレクションに挿入します。
const patientDocument = { patientName: "Jon Doe", patientId: 12345678, patientRecord: { ssn: "987-65-4320", billing: { type: "Visa", number: "4111111111111111", }, billAmount: 1500, }, }; const encryptedCollection = encryptedClient .getDB(encryptedDatabaseName) .getCollection(encryptedCollectionName); const insertResult = await encryptedCollection.insertOne(patientDocument);
ユーザの個人情報を説明するサンプルドキュメントを作成します。 次の例に示すように、暗号化されたクライアントを使用して、 patients
コレクションに挿入します。
var patient = new Patient { PatientName = "Jon Doe", Id = new ObjectId(), PatientRecord = new PatientRecord { Ssn = "987-65-4320", Billing = new PatientBilling { CardType = "Visa", CardNumber = 4111111111111111, }, BillAmount = 1500 } }; var encryptedCollection = encryptedClient.GetDatabase(encryptedDatabaseName). GetCollection<Patient>(encryptedCollectionName); encryptedCollection.InsertOne(patient);
ユーザの個人情報を説明するサンプルドキュメントを作成します。 次の例に示すように、暗号化されたクライアントを使用して、 patients
コレクションに挿入します。
patientDocument := &PatientDocument{ PatientName: "Jon Doe", PatientID: 12345678, PatientRecord: PatientRecord{ SSN: "987-65-4320", Billing: PaymentInfo{ Type: "Visa", Number: "4111111111111111", }, BillAmount: 1500, }, } coll := encryptedClient.Database(encryptedDatabaseName).Collection(encryptedCollectionName) _, err = coll.InsertOne(context.TODO(), patientDocument) if err != nil { panic(fmt.Sprintf("Unable to insert the patientDocument: %s", err)) }
このチュートリアルでは、ドキュメント構造を表すデータモデルとして POJO を使用します。 POJO を使用するようにアプリケーションを設定するには、次のコードを追加します。
CodecProvider pojoCodecProvider = PojoCodecProvider.builder().automatic(true).build(); CodecRegistry pojoCodecRegistry = fromRegistries(getDefaultCodecRegistry(), fromProviders(pojoCodecProvider));
Java POJO について詳しくは、 Wikipedia で Plain Old Java Object に関する記事を参照してください。
このチュートリアルでは、次の POJO を使用します。
Patient
PatientRecord
PatientBilling
これらのクラスは、完全なJavaアプリケーションのモデルパッケージで表示できます。
これらの POJO クラスをアプリケーションに追加します。 次に、対象の個人情報を記述するPatient
のインスタンスを作成します。 次の例に示すように、暗号化されたクライアントを使用して、 patients
コレクションに挿入します。
MongoDatabase encryptedDb = encryptedClient.getDatabase(encryptedDatabaseName).withCodecRegistry(pojoCodecRegistry); MongoCollection<Patient> collection = encryptedDb.getCollection(encryptedCollectionName, Patient.class); PatientBilling patientBilling = new PatientBilling("Visa", "4111111111111111"); PatientRecord patientRecord = new PatientRecord("987-65-4320", patientBilling, 1500); Patient patientDocument = new Patient("Jon Doe", patientRecord); InsertOneResult result = collection.insertOne(patientDocument);
ユーザの個人情報を説明するサンプルドキュメントを作成します。 次の例に示すように、暗号化されたクライアントを使用して、 patients
コレクションに挿入します。
const patientDocument = { patientName: "Jon Doe", patientId: 12345678, patientRecord: { ssn: "987-65-4320", billing: { type: "Visa", number: "4111111111111111", }, billAmount: 1500, }, }; const encryptedCollection = encryptedClient .db(encryptedDatabaseName) .collection(encryptedCollectionName); const result = await encryptedCollection.insertOne(patientDocument);
ユーザの個人情報を説明するサンプルドキュメントを作成します。 次の例に示すように、暗号化されたクライアントを使用して、 patients
コレクションに挿入します。
$patientDocument = [ 'patientName' => 'Jon Doe', 'patientId' => 12345678, 'patientRecord' => [ 'ssn' => '987-65-4320', 'billing' => [ 'type' => 'Visa', 'number' => '4111111111111111', ], 'billAmount' => 1500, ], ]; $encryptedCollection = $encryptedClient ->getDatabase($encryptedDatabaseName) ->getCollection($encryptedCollectionName); $result = $encryptedCollection->insertOne($patientDocument);
ユーザの個人情報を説明するサンプルドキュメントを作成します。 次の例に示すように、暗号化されたクライアントを使用して、 patients
コレクションに挿入します。
patient_document = { "patientName": "Jon Doe", "patientId": 12345678, "patientRecord": { "ssn": "987-65-4320", "billing": { "type": "Visa", "number": "4111111111111111", }, "billAmount": 1500, }, } encrypted_collection = encrypted_client[encrypted_database_name][encrypted_collection_name] result = encrypted_collection.insert_one(patient_document)
ユーザの個人情報を説明するサンプルドキュメントを作成します。 次の例に示すように、暗号化されたクライアントを使用して、 patients
コレクションに挿入します。
let patient_document = doc! { "patientName": "Jon Doe", "patientId": 12345678, "patientRecord": { "ssn": "987-65-4320", "billing": { "type": "Visa", "number": "4111111111111111", }, "billAmount": 1500, } }; let encrypted_coll: Collection<Document> = encrypted_client .database(encrypted_database_name) .collection(encrypted_collection_name); let insert_result = encrypted_coll.insert_one(patient_document).await?;
次のステップ
Queryable Encryption 対応コレクションを作成したら、暗号化されたフィールドをクエリできます。