Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 此atlas层中不允许$cond_Node.js_Mongodb_Mongoose - Fatal编程技术网

Node.js 此atlas层中不允许$cond

Node.js 此atlas层中不允许$cond,node.js,mongodb,mongoose,Node.js,Mongodb,Mongoose,只有当mongoose中的聚合管道中的条件满足时,我才必须执行搜索 const products = await this.product.aggregate([ {"$cond":[request.query.search!=undefined, { $match: { $text: { $search: request.query.search } } } ]}, //other aggregate operators

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

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

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

正如你在书中读到的,
$cond
必须在类似
$project

的内部使用。这个语法看起来有点错误
request.query.search=未定义
这在本地有效吗?