聚合 mongodb 错误:没有重载与此调用匹配

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

我正在尝试从 mongodb 进行聚合,这是代码:

const reports = await FullProfile.aggregate([
    {
      $match: {
        updatedAt: {
          $gte: dateFilter.startDate,
          $lte: dateFilter.endDate,
        },
        $or: [
          { $and: [{ manuallyMarkedAsDoneAt: { $exists: false } }] },
          {
            $and: [
              {
                manuallyMarkedAsDoneAt: {
                  $exists: true,
                  $gte: { $dateSubtract: { startDate: '$updatedAt', unit: 'minute', amount: 1 } },
                },
              },
            ],
          },
        ],
      },
    },
    {
      $project: {
        report: 'profile',
        query: '$username',
        totalPost: '$totalUniquePost',
        estimatedPost: '$availableVideo',
        postCoverage: {
          $cond: {
            if: { $gt: ['$availableVideo', 0] },
            then: { $divide: ['$totalUniquePost', '$availableVideo'] },
            else: 0,
          },
        },
        hasMore: {
          $toBool: '$hasMore',
        },
        updatedAt: '$updatedAt',
      },
    },
    {
      $match: {
        $or: [
          { estimatedPost: { $gte: 1000 }, totalPost: { $lte: 600 } },
          { estimatedPost: { $lt: 1000, $gte: 500 }, postCoverage: { $lte: 0.7 } },
          { estimatedPost: { $lt: 500, $gte: 100 }, postCoverage: { $lte: 0.8 } },
          { estimatedPost: { $lt: 100, $gte: 1 }, postCoverage: { $lte: 0.9 } },
        ],
      },
    },
  ]).exec();

编译后,我收到此错误:

src/services/dashboard.service.ts:33:9 - error TS2769: No overload matches this call.
  Overload 1 of 2, '(pipeline?: PipelineStage[] | undefined, options?: AggregateOptions | undefined, callback?: Callback<any[]> | undefined): Aggregate<any[]>', gave the following error.
    Type '({ $and: { manuallyMarkedAsDoneAt: { $exists: false; }; }[]; } | { $and: { manuallyMarkedAsDoneAt: { $exists: true; $gte: { $dateSubtract: { startDate: string; unit: string; amount: number; }; }; }; }[]; })[]' is not assignable to type 'Expression'.
  Overload 2 of 2, '(pipeline: PipelineStage[], callback?: Callback<any[]> | undefined): Aggregate<any[]>', gave the following error.
    Type '({ $and: { manuallyMarkedAsDoneAt: { $exists: false; }; }[]; } | { $and: { manuallyMarkedAsDoneAt: { $exists: true; $gte: { $dateSubtract: { startDate: string; unit: string; amount: number; }; }; }; }[]; })[]' is not assignable to type 'Expression'.

33         $or: [

我还是不明白错误在哪里,也许你们可以帮助我:(

我试图更改块 $or 和 $and 逻辑,但似乎错误并没有消失

database mongodb mongoose aggregate overloading
1个回答
0
投票

谢谢大家,我找到了解决问题的方法,我只需要更新 mongoose 库,我将 mongoose v6.1.1 更改为 v6.5.5,问题就解决了

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