$filter 无法识别的参数:限制 MongoDB-Mongoose

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

我的控制台出现以下错误:: 无效的 $project :: 由 :: Unrecognized parameter to $filter: limit

具有讽刺意味的是,文档告诉我们它存在并且可以使用。

这是我的代码

const docWorker = await _worker.aggregate([
    {
      $project: {
        credencial: {
          $cond: {
            if: {
              $eq: [{ $size: "$identificacionObra" }, 0],
            },
            then: false,
            else: {
              $cond: {
                if: {
                  $gte: [
                    {
                      $size: {
                        $filter: {
                          input: "$identificacionObra",
                          cond: {
                            $eq: ["$$credencial.estado", true],
                          },
                          as: "credencial",
                          limit: 1,  <--------- the limit parameter does not work
                        },
                      },
                    },
                    1,
                  ],
                },
                then: true,
                else: false,
              },
            },
          },
        },
      },
    },
    { $match: _match },
    { $sort: _sort },
    {
      $facet: {
        paginatedResults: [
          { $skip: req.query.page * req.query.limit - req.query.limit },
          { $limit: parseInt(req.query.limit) },
        ],
        totalCount: [
          {
            $count: "count",
          },
        ],
      },
    },
  ]);

请帮帮我,我做错了什么?

javascript node.js mongodb mongoose
1个回答
0
投票

检查 MongoDb 的版本,过滤器中的限制仅在 6.0 中可用

这里是 5.0 的文档https://www.mongodb.com/docs/v5.0/reference/operator/aggregation/filter/

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