I have this models:
class Sub(EmbeddedDocument):
name = StringField()
class Main(Document):
subs = ListField(EmbeddedDocumentField(Sub))
When i use this query, it returns all of Main
data but i just need subs
that their name
is 'foo'
.
query: Main.objects(__raw__={'subs': {'$elemMatch': {'name': 'foo'}}})
For example with this data:
{
subs: [
{'name': 'one'},
{'name': 'two'},
{'name': 'foo'},
{'name': 'bar'},
{'name': 'foo'}
]
}
The result must be:
{
subs: [
{'name': 'foo'},
{'name': 'foo'}
]
}
Note that in mongodb client, that query returns this values.