对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

KeyVault.deleteKey()(mongosh方法)

KeyVault.deleteKey(UUID)

从与数据库连接关联的密钥保管库中删除具有指定 UUID 的数据加密密钥。

返回:

指示已删除键数量的文档。

此命令可用于以下环境中托管的部署:

  • MongoDB Atlas:用于云中 MongoDB 部署的完全托管服务

deleteKey() 通过以下语法实现:

keyVault = db.getMongo().getKeyVault()
keyVault.deleteKey(UUID("<UUID String>"))

The UUID is a BSON binary data object with subtype 4.

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:

The following example is intended for rapid evaluation of client-side field level encryption. For specific examples of using KeyVault.deleteKey() with each supported KMS provider, see Delete a Data Encryption Key.

1

启动mongosh客户端。

mongosh --nodb
2

要为本地托管的密钥配置客户端字段级加密,请生成一个不带换行符的 base64 编码的 96 字节字符串。

const TEST_LOCAL_KEY = require("crypto").randomBytes(96).toString("base64")
3

使用生成的本地密钥字符串创建客户端字段级加密选项:

let autoEncryptionOpts = {
"keyVaultNamespace" : "encryption.__dataKeys",
"kmsProviders" : {
"local" : {
"key" : BinData(0, TEST_LOCAL_KEY)
}
}
}
4

使用配置了客户端字段级加密选项的Mongo()构造函数来创建数据库连接。 将mongodb://myMongo.example.net URI 替换为目标集群的连接字符串 URI

encryptedClient = Mongo(
"mongodb://myMongo.example.net:27017/?replSetName=myMongo",
autoEncryptionOpts
)

Retrieve the KeyVault object and use the KeyVault.deleteKey() method to delete the data encryption key with matching UUID:

keyVault = encryptedClient.getKeyVault()
keyVault.deleteKey(UUID("b4b41b33-5c97-412e-a02b-743498346079"))

If successful, deleteKey() returns output similar to the following:

{ "acknowledged" : true, "deletedCount" : 1 }
给本页内容打分