按时间段分组的Mongo汇总

时间:2020-03-19 06:05:36

标签: mongodb

我在mongo数据库中具有以下结构,(不同的时间来自数据库),

    {
      {
       _id:ObjectId(5e64be116c0a0b7d40e9387a), 
       "macid":"40:A3:6B:70:01:FE"
       "readings":{
          "timestamp":1521438794
          "log":"last log with time"
        }
     },
    {
       _id:ObjectId(5e64be116c0a0b7d40e9387a), 
       "macid":"40:A3:6B:70:01:FE"
       "readings":{
          "timestamp":1584597196
          "log":"last log with time"
        }
    },
    {
       _id:ObjectId(5e64be116c0a0b7d40e9387a), 
       "macid":"40:A3:6B:70:01:FE"
       "readings":{
          "timestamp":1584597607
          "log":"last log with time"
        }
     }
}

文档中存在不同的纪元时间。 我想以本地时区以以下格式获取数据。

{
"19 March 2020 ":[
   {
   "log":"last log with time",
   "timestamp" :"11:23:16"},
{
   "log":"last log with time",
   "timestamp" :"11:30:07"},
    ],
"9 March 2018":[{
   "log":"last log with time",
   "timestamp" :"11:23:14"}
    ]
}

是否可以通过mongo查询?。我尝试过,但无法正常工作,查询很大,要粘贴到这里。

0 个答案:

没有答案