[英]Mongo aggregate query with forEach function in pymongo not working
[英]Trouble converting mongo shell aggregate function to pymongo
我已經為此苦苦掙扎了幾個小時,但我在網上找不到一個好的解決方案。
pipeline = [
{"$project":
{
"index": {"$cond": { {"$and":[{ "$gt": [{ "$indexOfArray": ["$index.championId", 17]}, 5]},
{"$lt": [{ "$indexOfArray": ["$index.championId", 22]}, 6]}]}
,{"$slice": ["$playerInfo.info", 0, 5]}, {"$slice": ["$playerInfo.info", 5, 5]}}},
"team_a_champ": { "$slice": ["$playerInfo.info.championId", 0, 5]},
"team_b_champ": { "$slice": ["$playerInfo.info.championId", 5, 5]}
}},
{ "$match": { "$or":[
{ "$and":[{ "team_a_champ" : 17 }, {"team_b_champ":22}, {"index.stats.win":True}]},
{ "$and":[{ "team_a_champ" : 22 }, {"team_b_champ":17}, {"index.stats.win":True}]}]}},
{
"$project":
{
"new_idx": {"$arrayElemAt": ["$index", {"$indexOfArray": ["$index.championId", 17]}]}
}
},
{
"$project":
{
"stats": ["$new_idx.stats.item0", "$new_idx.stats.item1", "$new_idx.stats.item2", "$new_idx.stats.item3",
"$new_idx.stats.item4", "$new_idx.stats.item5"]
}
},
{
"$sort":
{"stats": -1}
},
{"$unwind": "$stats"},
{
"$group":
{
"_id": "$stats",
"count": {"$sum": 1}
}
},
{"$match": {"_id": {"$gt": 0}}},
{"$sort": {"count":-1, "_id": -1}},
{"$limit": 6}
]
我已經在重要部分周圍放置了字符串,但它只返回TypeError:不可散列的類型:'dict',而在mongoShell db中則起作用。
請幫忙! 或者至少給我一些舒適的文檔,說明如何進行轉換。 我什么都找不到!
我遇到的問題是$ cond標記中缺少“ if”,“ then”和“ else”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.