Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
evg-allegro opened this issue Dec 25, 2022 · 1 comment

Comments

@evg-allegro
Copy link

evg-allegro commented Dec 25, 2022

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"

@oren-allegro
Copy link

Any update on this?
Happens with MongoEngine 0.24.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants