我试图将聚合运算符与猫鼬一起使用,但出现以下错误:
<块引用>“无法识别的表达式 $regexMatch
”
let data = await Product.aggregate([
{ $match: { product_name: { $regex: /iphone/i } } },
{
$project: {
product_name: 1,
is_starting_match: {
$regexMatch: { input: '$product_name', regex: /^iphone/i },
},
price: {
$convert: {
input: { $arrayElemAt: ['$stores.storePrice', 0] },
to: 'int',
onError: 0,
onNull: 0,
},
},
},
},
{ $sort: { price: -1 } },
]);