T
T
TechNOIR2020-10-02 12:36:16
MongoDB
TechNOIR, 2020-10-02 12:36:16

MongoDB. How to build a query in this case?

Hello.

I recently started to comprehend mongodb, but I don’t understand how to correctly build a query in this case.
There is data of the following type.

{ 
    "_id" : "DBtxpeHsdhHGozhq8Dr", 
    "connections" : [
        {
            "id" : "KLLbGZTu9EuM2PrRt", 
            "instanceId" : "uJqr6jn131Bibp4HK", 
            "status" : "online", 
            "_createdAt" : ISODate("2020-09-30T07:45:19.116+0000"), 
            "_updatedAt" : ISODate("2020-10-02T09:30:43.923+0000")
        }, 
        {
            "id" : "zxKNGdwPDafRK7ary", 
            "instanceId" : "uJqr6jn131Bibp4HK", 
            "status" : "online", 
            "_createdAt" : ISODate("2020-10-02T07:59:44.381+0000"), 
            "_updatedAt" : ISODate("2020-10-02T09:30:43.892+0000")
        }, 
        {
            "id" : "udtzoheBCF5ZsmgPi", 
            "instanceId" : "uJqr6jn131Bibp4HK", 
            "status" : "online", 
            "_createdAt" : ISODate("2020-10-02T07:59:44.571+0000"), 
            "_updatedAt" : ISODate("2020-10-02T09:30:44.362+0000")
        }, 
        {
            "id" : "toPdumx8QSo5mAL46", 
            "instanceId" : "uJqr6jn131Bibp4HK", 
            "status" : "online", 
            "_createdAt" : ISODate("2020-10-02T07:59:44.643+0000"), 
            "_updatedAt" : ISODate("2020-10-02T09:30:44.504+0000")
        }
    ]
}


As a result, I need to get the number of connections where _updatedAt is between dates (let's say for 01.10). How to formulate a question in this case?

thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Max, 2020-10-02
@7workers

you have to use aggregation https://docs.mongodb.com/manual/aggregation/
array "connections" unwind ($unwind) filter ($match) and combine ($count)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question