KeyVault.addKeyAlternateName(UUID, keyAltName)UUIDを使用してデータ暗号化キーのkeyAltNames配列にkeyAltNameを追加します。keyAltNameは、キーヴォールト内のすべてのキー間で一意である必要があります。 メソッドは、getKeyVault()が存在するドキュメントのみを対象とする 部分インデックスkeyAltNamesフィルターを使用して、 フィールドに 一意のインデックスkeyAltNamesを自動的に作成します。次の値を返します。 データ暗号化キー ドキュメントの前のバージョンを返します。
データ暗号化キーに
UUID()が指定されていない場合は、nullを返します。
互換性
このコマンドは、次の環境でホストされている配置で使用できます。
- MongoDB Atlas はクラウドでの MongoDB 配置のための完全管理サービスです
MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン
MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン
構文
addKeyAlternateName() の構文は次のとおりです。
keyVault = db.getMongo().getKeyVault() keyVault.addKeyAlternateName( UUID("<UUID string>"), "keyAlternateName" )
動作
データベース接続にクライアント側のフィールドレベル暗号化を構成する必要があります
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 following example is intended for rapid evaluation of client-side field level encryption. For specific examples of using KeyVault.addKeyAlternateName() with each supported KMS provider, see Encryption Key Management.
暗号化されたクライアントの作成
データベース接続を作成するには、クライアント側のフィールドレベル暗号化オプションが構成されたMongo()コンストラクターを使用します。 mongodb://myMongo.example.net URI を、ターゲットクラスターの接続string URIに置き換えます。
encryptedClient = Mongo( "mongodb://myMongo.example.net:27017/?replSetName=myMongo", autoEncryptionOpts )
Retrieve the KeyVault object and use the KeyVault.addKeyAlternateName() method to add a new key alternate name to the data encryption key with matching UUID. The specified key alternate name must be unique:
keyVault = encryptedClient.getKeyVault() keyVault.addKeyAlternateName(UUID("b4b41b33-5c97-412e-a02b-743498346079"),"Other-Data-Encryption-Key")
If successful, addKeyAlternateName() returns the previous version of data encryption key document:
{ "_id" : UUID("b4b41b33-5c97-412e-a02b-743498346079"), "keyMaterial" : BinData(0,"PXRsLOAYxhzTS/mFQAI8486da7BwZgqA91UI7NKz/T/AjB0uJZxTvhvmQQsKbCJYsWVS/cp5Rqy/FUX2zZwxJOJmI3rosPhzV0OI5y1cuXhAlLWlj03CnTcOSRzE/YIrsCjMB0/NyiZ7MRWUYzLAEQnE30d947XCiiHIb8a0kt2SD0so8vZvSuP2n0Vtz4NYqnzF0CkhZSWFa2e2yA=="), "creationDate" : ISODate("2019-08-12T21:21:30.569Z"), "updateDate" : ISODate("2019-08-12T21:21:30.569Z"), "status" : 0, "version" : Long(0), "masterKey" : { "provider" : "local" }, "keyAltNames" : [ ] }
データ暗号化キー ドキュメントの現在のバージョンを表示するには、返されたドキュメントの_idを指定するKeyVault.getKey()を使用するか、 keyAltNamesの 1 つを指定するKeyVault.getKeyByAltName()を使用します。
Tip