0

I have an object that looks something like this in the database, with corresponding MongoEngine models:

{
    ...
    "config" : {
        "inner_group" : {
            "individuals" : [
                {
                    "entity_id" : "54321",
                }
            ],
        },
        ...    
    }
    ...
}

I am trying to query this data using the entity_id field in the object which is part of the individuals collection.

I have tried querying according to the MongoEngine docs but I have not been able to pull the data using the following:

data = Model.objects(config__inner_group__individuals__S__entity_id="54321")

How can I query the entire parent based on the entity_id?

Community
  • 1
  • 1
Felipe
  • 10,606
  • 5
  • 40
  • 57
  • 2
    `config__inner_group__individuals__entity_id="54321"` – Neil Lunn Sep 20 '17 at 21:48
  • Is it really that simple? So it doesn't matter that it's in an array then? I didn't even try it, because of section 2.5.2.3 on lists – Felipe Sep 20 '17 at 21:56
  • 2
    It's really that simple. You just read the wrong part of documentation. This is basically ["Dot Notation"](https://docs.mongodb.com/manual/core/document/#dot-notation) as covered in the core manual. The MongoEngine ( or django like ) way is to use `__` in place of `.`. – Neil Lunn Sep 20 '17 at 21:58

0 Answers0