1
每次向MongoDB集合添加文檔時,我都會保存當前時間Date.now()
。比方說,按照下面的格式這3個文件:MongoDB聚合或獲取集合中記錄文檔的平均每日平均數
# Doc 1
{
date: ISODate("2017-01-25T09:47:40.000Z"),
reports: 5
}
# Doc 2
{
date: ISODate("2017-01-24T09:47:40.000Z"),
reports: 5
}
# Doc 3
{
date: ISODate("2017-01-23T09:47:40.000Z"),
reports: 5
}
基本上,數學公式是(total reports) divided by the (count of days from the oldest date until date today)
。
使用mongo shell做這種聚合最簡單/最快的方法是什麼?
謝謝!
謝謝你,真的很有幫助!如果我不想將它們分組是因爲我只想獲得所有報告的平均每日平均值,那麼我只需刪除'_id'中的所有內容? – uncleCHEF
是啊改變'_id:null' – Veeram
嗨,我已經更新了我的問題,以獲得平均每日平均提供的數學公式。你能幫我矇混過關嗎?先謝謝了! – uncleCHEF