Node.js 此atlas层中不允许$cond
只有当mongoose中的聚合管道中的条件满足时,我才必须执行搜索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
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=未定义
这在本地有效吗?