How to query a document

I have a collection named MeasureData and try to find a specific document.
I’m trying to do this on studio 3T by the way.

The document looks like

{ 
    "_id" : "gETGXui6YhHknQXgr", 
    "createdAt" : ISODate("2022-05-05T14:41:58.567+0000"), 
    "value" : "1", 
    "measureId" : "JcZ23X5nbBMoJmRrk", 
    "creatorDetails" : {
        "uuid" : "wD7BaeY6SsNSBgjbg", 
        "responseId" : "xzPAXsFqFXb9DNwWN"
    }, 
    "updatedAt" : ISODate("2022-05-05T14:41:58.569+0000"), 
    "valueMeta" : {

    }, 
    "sample" : false, 
    "createdAtMeta" : {
        "year" : NumberInt(2022), 
        "month" : NumberInt(4), 
        "day" : NumberInt(5)
    }
}

I would like to filter by only measureId and creatorDetails.uuid but this below doesn’t filter the document.

db.getCollection("MeasureData").find({
    "creatorDetails" : {
        "uuid" : "wD7BaeY6SsNSBgjbg", 
    }, 
        "measureId": "JcZ23X5nbBMoJmRrk",
})

And I found out if I added “responseId”, it worked.

db.getCollection("MeasureData").find({
    "creatorDetails" : {
        "uuid" : "wD7BaeY6SsNSBgjbg", 
        "responseId" : "xzPAXsFqFXb9DNwWN" // added
    }, 
        "measureId": "JcZ23X5nbBMoJmRrk",
})

Do I have to have a creatorDetails.responseId query all the time to filter above document?

Thank you!

When you query for

you are asking for an equality condition on the object creatorDetails to match the object { uid:… }. But for 2 objects to be equals, you need all the same fields with all the same values in the same order.

You need to use dot notation such as:

"creatorDetails.uuid" : "wD7BaeY6SsNSBgjbg"

Like this you ask for the field uuid of the object creatorDetails to match the given value.

2 Likes

@steevej

Oh my gosh You answer questions quickly all the time!

"creatorDetails.uuid" : "wD7BaeY6SsNSBgjbg"

And yes this works! Thank you Steeve

2 Likes