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

Add support for the elemMatch projection operator #2267

Merged
merged 4 commits into from
Mar 15, 2020
Merged

Add support for the elemMatch projection operator #2267

merged 4 commits into from
Mar 15, 2020

Conversation

abarto
Copy link
Contributor

@abarto abarto commented Feb 14, 2020

Add support for the $elemMatch projection operator on querysets. It works the same way "slice" does. Take for instance the following document structure:

class Bar(EmbeddedDocument):
            v = StringField()
            z = StringField()


        class Foo(Document):
            x = StringField()
            y = IntField()
            items = EmbeddedDocumentListField(Bar)

The following query

Foo.objects.fields(elemMatch__items={'z': 'some value'})

will return Foo objects where the items contain only the first Bar embedded document for which z is "some value", otherwise, the field will contain an empty string.
Closes #2268

@bagerard bagerard merged commit 7c53339 into MongoEngine:master Mar 15, 2020
@bagerard
Copy link
Collaborator

Thanks for the contribution @abarto !

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

Successfully merging this pull request may close these issues.

Add support for $elemMatch projection operator.
3 participants