{
"_id" : ObjectId("56d56366806ea50fbcdf4f7e"),
"mac" : [
"cc1be0701fa5"
],
"shop_id" : 3307,
"reported_info" : [
{
"reported_time" : ISODate("2016-03-01T17:39:50.844Z"),
"online_mac" : [
"mac1",
"mac2",
"mac3",
"mac4",
"mac5"
]
}
}
对于这样的数据库结构,如果要查询在shop_id
=3307的文档下,在reported_info
里有没有online_mac
为mac1
的记录,该如何查询?
假设该 Model 为 Shop,定义如上图。
如下查询可以实现 是否存在 shop_id=3306 且该 shop 的 reported_info 中的 online_mac 存在 mac1 的 shop
Shop.objects.filter(shop_id=3307).filter(reported_info__online_mac='mac1')
不太确定是不是你想要的, 请确认下