mongoengine icon indicating copy to clipboard operation
mongoengine copied to clipboard

Query MapField by a key that matches one of the field names in the nested document fails with a mongoengine.errors.InvalidQueryError

Open evg-allegro opened this issue 2 years ago • 1 comments

Here is the class hierarchy:

class DataItem(EmbeddedDocument):
    key = StringField(required=True)
    value = StringField(required=True)

class MyDoc(Document):
    data = MapField(
        field=EmbeddedDocumentField(DataItem)
    )
    

And the data in db:

{
    "_id" : ObjectId("63a87cb374d6bc3efd9ea570"),
    "data" : {
        "key" : {
            "key" : "1",
            "value" : "test"
        }
    }
}
{
    "_id" : ObjectId("63a87cb374d6bc3efd9ea571"),
    "data" : {
        "a" : {
            "key" : "2",
            "value" : "test"
        }
    }
}

The query MyDoc.objects(data__a__value="test").first() succeeds while the query MyDoc.objects(data__key__value="test").first() fails with mongoengine.errors.InvalidQueryError: Cannot resolve field "value"

evg-allegro avatar Dec 25 '22 17:12 evg-allegro

Any update on this? Happens with MongoEngine 0.24.2

oren-allegro avatar Apr 20 '23 07:04 oren-allegro