I have a document and an embedded document as shown below. And I would like to query the embedded document in mongoengine. In sql, this would be: SELECT A.Nom_PC, B.Intitule from Comptes as A, Vals as B WHERE B.Num = "some value"
class Vals(EmbeddedDocument):
Num = StringField()
Intitule = StringField()
meta = {'allow_inheritance': True}
class Comptes(Document):
Nom_PC = StringField()
PC = ListField(EmbeddedDocumentField(Vals))
meta = {'allow_inheritance': True}
I've tried out some things that didn't work like:
Comptes.objects(Vals__match={ "Num": Num }).aggregate(
{'$project': {
'PC': {
'$filter': {
'input': '$PC',
'as': 'Vals',
'cond': {'$eq': ['$$Vals.Num', Num]}
}
}
}}
)