Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.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 如何将$split运算符与聚合一起使用_Node.js_Mongodb_Mongoose_Aggregation Framework - Fatal编程技术网

Node.js 如何将$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

我想在日期字段上使用$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" :{
    "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 ] }
              }
          }
       ]
    )