getKeyVault()現在のデータベース接続の
KeyVaultオブジェクトを返します。KeyVaultオブジェクトは、クライアント側のフィールドレベル暗号化 のデータ暗号化キー管理をサポートしています。次の値を返します。 現在のデータベース接続の
KeyVaultオブジェクト。
互換性
このコマンドは、次の環境でホストされている配置で使用できます。
- MongoDB Atlas はクラウドでの MongoDB 配置のための完全管理サービスです
MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン
MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン
構文
getKeyVault() の構文は次のとおりです。
keyVault = db.getMongo().getKeyVault();
次のデータ暗号化キー管理メソッドにアクセスするには、 KeyVaultオブジェクトを使用します。
動作
データベース接続にクライアント側のフィールドレベル暗号化を構成する必要があります
次の例では、クライアント側のフィールドレベル暗号化構成にローカルで管理されているキーを使用しています。
The mongosh client-side field level encryption methods require a database connection with client-side field level encryption enabled. If the current database connection was not initiated with client-side field level encryption enabled, either:
Use the
mongoshcommand line options to establish a connection with the required options. The command line options only support the Amazon Web Services KMS provider for CMK management.
キーヴォールトの一意の部分インデックス
The getKeyVault() method automatically creates a unique index on the keyAltNames field with a partial index filter for only documents where keyAltNames exists. getKeyVault() creates this index in the key vault collection. This prevents any two data encryption keys in the same key vault from having the same key alternative name and therefore avoids ambiguity around which data encryption key is appropriate for encryption/decryption.
警告
Do not drop the unique index created by getKeyVault(). Client-Side Field Level Encryption operations depend on server-enforced uniqueness of keyAltNames. Removing the index may lead to unexpected or unpredictable behavior.
例
次の例では、クライアント側のフィールドレベル暗号化構成にローカルで管理されているキーを使用しています。
暗号化されたクライアントの作成
データベース接続を作成するには、クライアント側のフィールドレベル暗号化オプションが構成されたMongo()コンストラクターを使用します。 mongodb://myMongo.example.net URI を、ターゲットクラスターの接続string URIに置き換えます。
encryptedClient = Mongo( "mongodb://myMongo.example.net:27017/?replSetName=myMongo", autoEncryptionOpts )
Use the getKeyVault() method to retrieve the key vault object:
keyVault = encryptedClient.getKeyVault()
クライアント側のフィールドレベル暗号化を有効にして MongoDB 接続を開始する方法に関する詳細なドキュメントについては、 Mongo()を参照してください。