mongodb - Limit items returned in push with group -


I need a group by the sender (fleche) and get the last message from every one .. I have successfully considered this idea All messages have been reverted to each 'Fleet' (senders) on $ push and $ group . With the date of the message should be searched for the same PB, the last element. Is it possible with mouth 2.6.6 aggregation framework ?
Result expected, actual results from my actual query, actual query, and message compile sample bellow:
Expected Result:

  " Results ": [" _ id ": 1," date "[1421948851800]," mess ": [" extreme dirt ffsdfsdfsd 2 "]}, {" _ id ": 3," date "[1421948859593]," mess ": [" Darnier mess ffsdfsdfsd 2 "]}  

Actual results from the actual query:

 " Results ": [[" "_ Id": 1, "Date" [1421948851800, 1421947200606, 1421947163929, 1421947153646, 1421946853567], "Mess": ["Extreme dirt ffsdfsdfsd 2", "Fssdfencore ddone fd2", "fsd fd fd! 2", "whitefodus sdf fay2", "s alut la companie"]}, {"_ id": 3, "date" [1421948859593, 1421947176679, 1421947098168], "Glitch": ["Extreme dirt ffsdfsdfsd 2", "fssdfsdffsd ss fd2", "salut la companie"]}  

actual query:
{$ push: "$ date"}, P> Message archive sample:

  {"_ id": ObjectId ("54c12fe5a48da55ee08c7804"), "Fleche": 1, "Cible": 2 , "Date": 1421946853567, "Glitch": "Salut La companie", "Lu": {} {"_ Id ": ObjectId (" 54c130daa48da55ee08c7805 ")," Fleche ": 3," CIBLE ": 2," Date ": 1421947098168," Glitch ":" Salut La companie "," L.U. ": {" _ id " ("54c13111a48da55ee08c7807"), "Fleche": 1, "Cible": 2, "Date": 1421947153646, "Glitch": "safdsfdsfs sdf fie2", "lu": 0} {"_id": ObjectId (" "FSD FDS FDA 2", "Louis": {} {"_id": ObjectId ("54c13128a48da55ee08c7809"), "flec": 1, "cible": 2, "Date": 1421947163929, "Dirt" , "Fleche": 3, "cible": 2, "date": 1421947176679, "dirt": "fssdfsdffsd ss fds 2", "lu": 0}  / <> 

you or

  db.messages.aggregate ([{$ match: {cible: 2, Lu: 0}}, {$ sort: {date: -1}}, {$ group: {_id: "$ fleche", date: {$ first: "$ date"} , {$ First: "$ mess"}}}, {$ limit: 20}])  

The output will be:

  {"result ":" Dirt ":" FDD FDS FD2 "}, {" _id ": 3," Date ": 1421947176679," Dirt ":" fssdfsdffsd ss fds 2 ": [" {{"_id": 1, "Date": 1421947163929, "}]," Right ": 1}  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -