在mongodb中获取对象键的数据过滤值

时间:2019-01-30 15:33:52

标签: mongodb mongodb-query

这是我的文档结构

{
    "_id" : ObjectId("5c51b3e2bb564f3f1ccf84c2"),
    "createdAt" : 1548858338324,
    "updatedAt" : 1548858843028,
    "teamId" : "ef08f13",
    "analytics" : {
        "aggregate" : {
            "averageViewTime" : 5.6000000000000005,
            "averageClicks" : 2.5,
            "totalViews" : 2,
            "totalVisits" : 4
        },
        "days" : {
            "28-12-2018" : {
                "dayAvgViewTime" : 5.6000000000000005,
                "dayAvgClicks" : 2.5,
                "dayViews" : 2,
                "dayVisits" : 4
            },
            "20-01-2019" : {
                "dayAvgViewTime" : 5.6000000000000005,
                "dayAvgClicks" : 2.5,
                "dayViews" : 2,
                "dayVisits" : 4
            },

        }
    }
}

如果analytics.days对象的键在给定范围内匹配,我想获取记录。例如,如果我想要在开始日期"15-01-2019"和结束日期"25-01-2019"之间进行记录。它应该返回以下内容:

{
    "_id" : ObjectId("5c51b3e2bb564f3f1ccf84c2"),
    "createdAt" : 1548858338324,
    "updatedAt" : 1548858843028,
    "teamId" : "ef08f13",
    "analytics" : {
        "aggregate" : {
            "averageViewTime" : 5.6000000000000005,
            "averageClicks" : 2.5,
            "totalViews" : 2,
            "totalVisits" : 4
        },
        "days" : {
            "20-01-2019" : {
                "dayAvgViewTime" : 5.6000000000000005,
                "dayAvgClicks" : 2.5,
                "dayViews" : 2,
                "dayVisits" : 4
            },

        }
    }
}

0 个答案:

没有答案