Filter list of embedded documents with reference field

霸气de小男生 提交于 2019-12-23 04:45:16

问题


I'm pretty new to MongoDB and I'm experiencing it with mongoengine. Given this 'User' model where 'bets' is an embedded document list which each element contains a reference to a 'match' document,

{ 
  "_id" : ObjectId("53df77cef4c9610f28cbff14"), 
  "name" : "Test", 
  "admin" : false, 
  "bets" : [ 
             { "match" : ObjectId("53e1511df4c9610bf52f5b7a"), "expectedResult" : "1" } 
           ] 
 }

how can I get 'bets' elements, passed to query the matchId?

I tried to do

User.objects.filter(bets__match={'match._id':match.id})

where 'match' is the object I need to filter by but I get an empty array.

来源:https://stackoverflow.com/questions/25180853/filter-list-of-embedded-documents-with-reference-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!