我需要使用聚合函数在 MongoDB 中获取字符串值的长度。
它适用于
db.collection_name.find({"$where":"this.app_name.length===12"})
但是当植入到
db.collection_name.aggregate({$match:
{"$where":"this.app_name.length===12"}
},
{
$group :
{
_id : 1,
app_downloads : {$sum: "$app_downloads"}
}
}
);
我得到了这个结果:
failed: exception: $where is not allowed inside of a $match aggregation expression
问题是:是否可以在聚合函数中使用 $where ?或者有什么方法可以在聚合函数中获取字符串值的长度?
提前感谢埃里克