Mongodb 3.4.7 Aggregation Convert ptms time to seconds

自古美人都是妖i 提交于 2019-12-24 22:00:48

问题


I have the following json:

{  
   "statement":{  
      "result":{  
         "duration":"PT0.552S",
         "completion":true,
         "success":false
      }
   },
   "statement":{  
      "result":{  
         "duration":"PT0.552S",
         "completion":true,
         "success":false
      }
   },
   "statement":{  
      "result":{  
         "duration":"PT0.552S",
         "completion":true,
         "success":false
      }
   }
}

How can I write a mongo aggregator to getting the statement -> result -> duration time format that now in ptms string to seconds?

I need something like:

    [
        1131,
        648,
        1678,
        .....
        .....
    ] 

Here each number is the duration that is converted into seconds.

Here : http://docs.mongodb.com/manual/reference/operator/aggregation/hour I can see : "date" : ISODate("2014-01-01T08:15:39.736Z") but how to use it for ptms time format?

I am encoding these aggregators and passing in query parameters to server to get the result. So how to use ISODate in query parameter ? How can I encode it? say like encode the following json format and pass it in GET query parameters:

 { 
        "$project": {
      "duration": "$ISODate('$statement.result.duration')"
        }
  }

来源:https://stackoverflow.com/questions/51152423/mongodb-3-4-7-aggregation-convert-ptms-time-to-seconds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!