Mongo aggregation within intervals of time

前端 未结 3 951
孤独总比滥情好
孤独总比滥情好 2021-02-04 20:57

I have some log data stored in a mongo collection that includes basic information as a request_id and the time it was added to the collection, for example:

{
            


        
3条回答
  •  离开以前
    2021-02-04 21:29

    a pointer in lieu of a concrete answer. you can very easily do it for minutes, hours and given periods using the date aggregations . every 10 minutes will be a bit trickier but likely possible with some wrangling. nevertheless, the aggregation will be slow as nuts on large data sets.

    i would suggest extracting the minutes post-insert

    {
        "_id" : ObjectId("55ae6ea558a5d3fe018b4568"),
        "request_id" : "030ac9f1-aa13-41d1-9ced-2966b9a6g5c3",
        "time" : ISODate("2015-07-21T16:00:00.00Z"),
        "minutes": 16
    }
    

    and even though it sounds utterly absurd adding quartiles and sextiles or whatever that N might be.

    {
        "_id" : ObjectId("55ae6ea558a5d3fe018b4568"),
        "request_id" : "030ac9f1-aa13-41d1-9ced-2966b9a6g5c3",
        "time" : ISODate("2015-07-21T16:00:00.00Z"),
        "minutes": 16,
        "quartile: 1,
        "sextile: 2,
    }
    

    first try doing a $div on the minutes. doesnt do ceil and floor. but check out

    Is there a floor function in Mongodb aggregation framework?

提交回复
热议问题