0
文章MongoBD計數我有一個MongoDB的設置如下:與作者
{_id: id,
'article_information': ...
'AU':[list of authors]
..other fields...
}
我試圖使用聚合計算的文件(文章)每每個作者的數量。在這一點上重複都可以。合併作者是另一層處理,由於名稱的改變,名稱的不同拼寫以及重音等等。
我想類似以下的輸出:
'Author 1': Count of documents mentioning author 1,
...
'Author N': Count of documents mentioning author n,
下面的嘗試得到一個空列表:
collection.aggregate([{"$group":{"_id":'AU',"count":{"$sum":1}}}])
我認爲錯誤可能是因爲$AU
是一個字符串列表,但db.collection.distinct('AU')
返回字符串列表,而不是列表列表。
在SQL樣式語法中,我將查詢視爲放入迭代作者列表的for循環中。我不知道如何在Mongo中編寫它。
SELECT * from collection WHERE author IN AUTHOR_LIST