Node.js 如何将$split运算符与聚合一起使用
我想在日期字段上使用$split运算符Node.js 如何将$split运算符与聚合一起使用,node.js,mongodb,mongoose,aggregation-framework,Node.js,Mongodb,Mongoose,Aggregation Framework,我想在日期字段上使用$split运算符 [{ "status": true, "beaconData" :{ "date" : "15/07/2017, 11:00", "charge" : 15, }, { "status": true, "beaconData" :{ "date" : "2/07/2017, 15:00", "charge" : 35, }, { "status": true, "beaconData" :{ "d
[{
"status": true,
"beaconData" :{
"date" : "15/07/2017, 11:00",
"charge" : 15,
},
{
"status": true,
"beaconData" :{
"date" : "2/07/2017, 15:00",
"charge" : 35,
},
{
"status": true,
"beaconData" :{
"date" : "2/07/2017, 11:05",
"charge" : 5,
}]
我曾经这样用过
聚合([{$project:{$data:{$split:[“$beaconData.date”,“,”]},'状态:1}}]))
但错误的返回像
“errmsg”:“异常:无效运算符“$split”
“代码”:15999
运算符在3.4版本中可用。是否有任何方法可以根据日期计算总费用,如[{'status':true,'beaconData':{'date':'2/07/2017','totalCharge':40},{'status':true,'beaconData':{'date':'15/07/2017','totalCharge':15},
//$split works in 3.4 u can use $substr in ur case if ur date is always in the same format you asked
db.orders.aggregate(
[
{
$project:
{
data: { $substr: [ "$beaconData.date", 0, 9 ] }
}
}
]
)