我是新來蒙戈骨料,蒙戈查詢:如何獲得last_activity使用聚合
我要求的用戶是顯示user
和他last_activity_time
和last_activity
。
Collection Object:
{
"_id" : ObjectId("123456"),
"activity_count" : NumberLong(0),
"dt" : ISODate("2014-02-18T20:45:00.001Z"),
"job_functions" : [ ],
"joined_time" : ISODate("2014-01-27T22:53:57.024Z"),
"views_cnt" : NumberLong(6),
"last_activity" : "Login",
"last_activity_time" : ISODate("2014-02-18T20:56:43.552Z"),
"locations" : [ ],
"user_id" : "123456",
"user_name" : "User 1"
}
{
"_id" : ObjectId("789034"),
"activity_count" : NumberLong(0),
"dt" : ISODate("2014-02-18T21:45:00.001Z"),
"job_functions" : [ ],
"joined_time" : ISODate("2014-01-27T22:53:57.024Z"),
"views_cnt" : NumberLong(6),
"last_activity" : "Page View",
"last_activity_time" : ISODate("2014-02-18T20:56:43.552Z"),
"locations" : [ ],
"user_id" : "123456",
"user_name" : "User 1"
}
我需要得到
{
_id: {
user_id: "123456"
},
key: "123456",
user_name: "Ba Pub",
last_activity_time: "2014-02-18T20:56:43.552Z",
joined_time: "2014-01-27T22:53:57.024Z",
last_activity: "Page View"
}
我面臨的問題是last_activity_time
,我可以得到max(last_activity_time)
,但last_activity是有點棘手。
任何幫助表示讚賞。
我的最終輸出應該是最活躍的用戶,這是基於** activity_count ** – user3438004
這是我已經想出的聚合查詢, – user3438004
謝謝,這解決了我的擔憂。 – user3438004