簡體   English   中英

pymongo聚合查詢我在做什么

[英]What I am doing wrong with this pymongo aggregate query

ff = db.collection.aggregate(
[
 { '$match': { "id_str":"1055193743425499137"} },
 { '$group': { "_id": "text", "No_of_Times": { '$sum': 1 } } }
]
 )
print(list(ff))

這是我收藏中的文件樣本。

{"_id":"5bd0d561f94f845d9cb70f39",
 "id":"1055193743425499137",
 "id_str":"1055193743425499137",
 "text":"RT @WeNeedEU: This,....."}

我正在嘗試使用匯總查詢來查找與id_str匹配的文檔數。 上面的代碼顯示了一個我不明白的空列表。 有人可以幫我嗎?

我對python不熟悉

下面的查詢在Mongo GUI上進行了測試。

aggregate(
[
 { '$match': { "id_str":"1055193743425499137"} },
 { '$group': { "_id": "$text", "No_of_Times": { '$sum': 1 } } } //change "text" with "$text"
]
 )

輸出:

{
    "_id" : "RT @WeNeedEU: This,.....",
    "No_of_Times" : 1.0
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM