DB集合就像:“suid”:“8986691b1db3d99b6fbe27cceac2e19c”,“auid”:“22e7e5632acb4ac154b9bcb95710ca38”,“msg”:“ceshi1”,“ctime”:ISODate(“2013-05-22T03:52:26.34Z”)发送”:真,“__v”:0,“_id”:ObjectId(“519c411351db351236000001”)
MongoDB shell 命令为:db.runCommand({"group":{ns:"messages",key:{"auid":true},"initial":{"lastmsgtime":0},condition:{auid:'456 '},$reduce:function(doc,prev){senttime=doc.ctime.valueOf();if(senttime>prev.lastmsgtime){prev.suid=doc.suid;prev.lastmsgtime=new Date(senttime); }}, } })
猫鼬可以做这个工作吗?