Mongodb find nested dict element

Question:

{
    "_id" : ObjectId("63920f965d15e98e3d7c450c"),
    "first_name" : "mymy",
    "last_activity" : 1669278303.4341061,
    "username" : null,
    "dates" : {
        "29.11.2022" : {

        },
        "30.11.2022" : {

        }
    },
    "user_id" : "1085116517"
}

How can I find all documents with 29.11.2022 contained in date? I tried many things but in all of them it detects the dot letter as something else.

Asked By: Dark

||

Answers:

Use $getField in $expr.

db.collection.find({
  $expr: {
    $eq: [
      {},
      {
        "$getField": {
          "field": "29.11.2022",
          "input": "$dates"
        }
      }
    ]
  }
})

Mongo Playground

Answered By: ray