0
以下是來自「Page」集合的一些文檔,我希望獲得字段「memberProfile_editAccountProfile」的總和?
{
"_id" : NumberLong(2013083117),
"count" : 3000,
"requests" : {
"consumermx" : {
"NFCU" : {
"memberDashboard_editDashboard" : 24,
"memberProfile_editAccountProfile" : 1,
"memberProfile_editPreferencesAssociation" : 1,
"memberProfile_editPromotionReminder" : 59,
"memberProfile_savePromotionReminder" : 6,
}
}
}
}
{
"_id" : NumberLong(2013083118),
"count" : 3000,
"requests" : {
"consumermx" : {
"NFCU" : {
"memberDashboard_editDashboard" : 12,
"memberProfile_editAccountProfile" : 23,
"memberProfile_editPreferencesAssociation" : 6,
"memberProfile_editPromotionReminder" : 21,
"memberProfile_savePromotionReminder" : 9,
}
}
}
}
如果您想根據「_id」字段的時間戳範圍過濾計數該怎麼辦? – Sohail
你可以在'$ group'之前放置一個'$ match'階段。 '$ match'的作用類似於find()查詢,並允許您只將符合條件的文檔傳遞給管道的其餘部分。請注意,'$ group'中的'_id'與原始文檔中的'_id'無關。我建議使用'ISODate()'值作爲時間戳而不是'NumberLong',因爲您從同一空間獲得更高的精度。 – drmirror
工作,謝謝! – Sohail