过滤django mongoengine的查询

时间:2014-09-26 12:23:58

标签: python django mongoengine flask-mongoengine

我有两个嵌入式文档和列表字段的视图,需要filteringquery 以下标准:

class myfriends(EmbeddedDocument):
    myfriends_ids = StringField()
        status = StringField()

class Friends(Document):
    friend1 = ReferenceField(User)
        myfriendslist = ListField(EmbeddedDocumentField(myfriends))

存储的值就像:

{ "_id" : ObjectId("542506f9bed069156ddd4476"), 
    "friend1" :     ObjectId("542314b7bed0691c5302662c"), 
    "myfriendslist" : [ 
        { 
            "myfriends_ids" : "5421ae74bed0691471e95b92", 
            "status" : "1" 
        } ]
}

我希望查询根据django mongoengine中的friend1myfriends_ids获取特定记录。

1 个答案:

答案 0 :(得分:0)

Friends.objects(myfriendslist__match={"myfriends_ids": "5421ae74bed0691471e95b92", "status": "1"}, friend1=FriendObject)