【问题标题】:$cond is not allowed in this atlas tier此 atlas 层中不允许使用 $cond
【发布时间】:2020-11-02 00:49:14
【问题描述】:

只有在 mongoose 的聚合管道中满足条件时,我才必须执行搜索

 const products = await this.product.aggregate([
      {"$cond":[request.query.search!=undefined,
        { $match: { $text: { $search: request.query.search } } }
      ]},
      //other aggregate operators
]);

目前,在这个 atlas 层中不允许使用 $cond 但我只能在聚合管道中使用它。知道我该怎么做吗?

【问题讨论】:

  • 这个语法看起来有点不对request.query.search!=undefined这在本地工作吗?

标签: node.js mongodb mongoose


【解决方案1】:

正如您在MongoDb docuemnt 中看到的那样,$cond 必须在$project 之类的内部使用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-15
    • 2013-11-30
    • 2023-03-04
    • 2014-05-28
    • 2013-02-01
    • 2018-11-06
    相关资源
    最近更新 更多