基于数组元素在Mongodb中过滤

时间:2017-05-09 07:04:36

标签: arrays mongodb

我有一个类似下面提到的文档结构

    {
    "_id" : ObjectId("asdasdasdasdasdas"),
    "info" : [ 
        {

          "dateTime" : ISODate("2016-08-19T12:10:16.000Z"),
          "srcName" : null,
          "parseFlag" : true,
          "GrId" : null,
          "eventMessage" : "Error1. "
        }, 
       {

          "dateTime" : ISODate("2016-09-19T12:10:16.000Z"),
          "srcName" : null,
          "parseFlag" : false,
          "GrId" : null,
          "eventMessage" : "Error2"
       },
       {

          "dateTime" : ISODate("2016-10-19T12:10:16.000Z"),
          "srcName" : null,
          "parseFlag" : false,
           "GrId" : null,
           "eventMessage" : "Error2"
        },
        ],
    "domain" : "asdasdas",  
    "fileName" : "sdasdsdfsd.dsf.gz",   
    "eventGroup" : "fault",   
    "eventId" : 62,
    "type" : "1"

     }

我必须根据信息中的日期时间过滤记录。例如,如果我必须单独获得八月份数据我该怎么做?

输出应该类似

   {
    "_id" : ObjectId("asdasdasdasdasdas"),
    "info" : [ 
    {

    "dateTime" : ISODate("2016-08-19T12:10:16.000Z"),
    "srcName" : null,
    "parseFlag" : true,
    "GrId" : null,
    "eventMessage" : "Error1. "
    }, 
    "domain" : "asdasdas",  
    "fileName" : "sdasdsdfsd.dsf.gz",   
    "eventGroup" : "fault",   
    "eventId" : 62,
    "type" : "1"
    }

使用聚合和展开会花费大量时间。 让我知道如何处理这种情况

0 个答案:

没有答案