Dark
Dark

Reputation: 25

Mongodb find nested dict element

{
    "_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.

Upvotes: 0

Views: 41

Answers (1)

ray
ray

Reputation: 15215

Use $getField in $expr.

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

Mongo Playground

Upvotes: 2

Related Questions