我收集了这样的文件:
{
"_id" : ObjectId("5c0685fd6afbd73b80f45338"),
"page_id" : "1234",
"category_list" : [
"football",
"sport"
],
"time_broadcast" : "09:13"
}
{
"_id" : ObjectId("5c0685fd6afbd7355f45338"),
"page_id" : "1234",
"category_list" : [
"sport",
"handball"
],
"time_broadcast" : "09:13"
}
{
"_id" : ObjectId("5c0694ec6afbd74af41ea4af"),
"page_id" : "123456",
"category_list" : [
"news",
"updates"
],
"time_broadcast" : "09:13"
}
....
now = datetime.datetime.now().time().strftime("%H:%M")
我想要的是:当“time_broadcast”等于“now”时,我得到每个“page_id”的不同“category_list”列表。
输出应如下所示:
{
{
"page_id" : "1234",
"category_list" : ["football", "sport", "handball"]
},
{
"page_id" : "123456",
"category_list" : ["news", "updates"]
}
}
我已经尝试过这样的:
category_list = db.users.find({'time_broadcast': now}).distinct("category_list")
但这给了我不同值的输出列表,但是
所有“page_id”:
["football", "sport", "handball","news", "updates"]
不是 page_id 的 Category_list 。
有什么帮助吗?
Thanks