Queryable Encryption equality and range queries are fully supported in production. Prefix, suffix, and substring queries are only available in public preview in MongoDB 8.2. Do not enable these query types in production. GA functionality of prefix, suffix and substring query types will be incompatible with the preview feature. To learn more, see Supported Query Types.
Overview
在创建集合时启用Queryable Encryption 。 您无法对已在集合中的文档上的字段进行加密。
重要
显式创建集合,而不是使用插入操作隐式创建集合。 当您使用 createCollection()创建集合时, MongoDB会在加密字段上创建索引。 如果没有此索引,对加密字段的查询可能会运行缓慢。
对集合启用 Queryable Encryption
您可以通过以下两种方式之一对字段启用 Queryable Encryption。 以下示例使用 Node.js 启用 Queryable Encryption:
将
encryptedFieldsObject常量表示的加密模式传递给应用程序用于创建集合的客户端:const client = new MongoClient(uri, { autoEncryption: { keyVaultNameSpace: "<your keyvault namespace>", kmsProviders: "<your kms provider>", extraOptions: { cryptSharedLibPath: "<path to Automatic Encryption Shared Library>" }, encryptedFieldsMap: { "<databaseName.collectionName>": { encryptedFieldsObject } } } ... await client.db("<database name>").createEncryptedCollection("<collection name>"); } 有关
autoEncryption配置选项的更多信息,请参阅适用于 Queryable Encryption 的 Queryable Encryption选项部分。将加密模式
encryptedFieldsObject传递给createEncryptedCollection():await encryptedDB.createEncryptedCollection("<collection name>", { encryptedFields: encryptedFieldsObject }); 提示
在创建集合以及创建客户端以访问权限集合时指定
encryptedFieldsObject。 有关不定义encryptedFieldsObject的安全注意事项的更多信息,请参阅安全注意事项。