NodeJS MongoDB CSFLE 聚合替换根错误

问题描述 投票:0回答:1

我在以下查询中收到此错误: 注意:打孔集合未加密,也没有任何加密的 CSLFE, 我有另一个包含 CSLFE 查询加密字段的集合。 仅供参考,如果我在指南针中手动添加阶段,它就可以工作

查询:

punches.aggregate([ { '$match': { '$and': [ { profileId: { '$in': [ new ObjectId('65a824c94528792470c0edf6'), new ObjectId('65a824cb4528792470c0ee5a'), new ObjectId('65a824d24528792470c0f01d'), new ObjectId('65a824d34528792470c0f053'), new ObjectId('65a824d44528792470c0f073'), new ObjectId('65a824d54528792470c0f0a2') ] } } ] } }, { '$match': { organizationId: new ObjectId('6507ae62881ea4139434fe9c'), punchDateTime: { '$gte': 2023-01-30T00:00:00.000Z, '$lte': 2024-01-30T00:00:00.000Z } } }, { '$skip': 0 }, { '$limit': 4000 }, { '$group': { _id: '$deviceCode', latestDocument: { '$first': '$$ROOT' } } }, { '$replaceRoot': { newRoot: '$latestDocument' } }, { '$sort': { deviceCode: 1, 'name.text': 1 } }], { allowDiskUse: true })

错误:

MongoCryptError: csfle "analyze_query" failed: Access to variable ROOT disallowed [Error 2, code 31127]
    at StateMachine.execute (D:\backend\node_modules\mongodb\src\client-side-encryption\state_machine.ts:271:13)
    at processTicksAndRejections (node:internal/process/task_queues:95:5) {stack: 'MongoCryptError: csfle "analyze_query" failed…ions (node:internal/process/task_queues:95:5)', message: 'csfle "analyze_query" failed: Access to variable ROOT disallowed [Error 2, code 31127]', Symbol(errorLabels): Set(0)}

为了更简单地查看查询,这是管道:

pipelines [
  {
    '$match': {
      organizationId: new ObjectId('6507ae62881ea4139434fe9c'),
      punchDateTime: {
        '$gte': 2023-01-30T00:00:00.000Z,
        '$lte': 2024-01-30T00:00:00.000Z
      }
    }
  },
  { '$skip': 0 },
  { '$limit': 4000 },
  {
    '$group': { _id: '$deviceCode', latestDocument: { '$first': '$$ROOT' } }
  },
  { '$replaceRoot': { newRoot: '$latestDocument' } },
  { '$sort': { deviceCode: 1, 'name.text': 1 } }
] 
mongodb aggregation-framework mongodb-csfle
1个回答
0
投票

csfle "analyze_query" failed
错误发生在客户端,而本地加密进程正在分析查询以确定是否需要获取任何密钥。使用“$ROOT”会使正在访问的字段变得复杂,从而使确定变得更加困难。开发人员显然采取了“安全”路线,并且在客户端启用 CSFLE 时拒绝使用
$ROOT
来接受聚合管道,而不是添加逻辑来确定这是否可能重要。

一种可能的解决方案是在代码中实例化 2 个 MongoClients,一个具有 autoEncryption 选项,另一个没有。当您需要使用 $ROOT 运行聚合时,请使用非加密客户端。

© www.soinside.com 2019 - 2024. All rights reserved.