can't query over ListField(EmbeddedDocumentField)

扶醉桌前 提交于 2019-12-06 05:12:40

You would need to do an $elemMatch[1] query and there is no inbuilt support for it in mongoengine at this time. You'd have to do a raw query like so:

Agent.objects.filter(
    name='ashraf',  
    __raw__={"skills": {
        "$elemMatch": {
            "level": {"$gt": 5}, 
            "name": "Computer Skills"
        }
    }}
)

[1] http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24elemMatch

I don't use python driver, but the general Mongo syntax for what you're trying to accomplish is this....

db.agent.find({name:'ashraf', 'skills.name' : "computer skills", level:{ $gt: 5}})
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!