Advertisement
Guest User

Untitled

a guest
May 1st, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. db.collection('checkpoint').aggregate
  2. [
  3. { '$match': {'id_journey': journey.id_journey} },
  4. { '$sort': { 'when': 1} },
  5. {
  6. '$group': {
  7. '_id': { $dateToString: { format: '%Y-%m-%d', date: '$when' } },
  8. 'day': {
  9. '$push': {
  10. 'id': '$id_checkpoint',
  11. 'when': '$when',
  12. 'type': '$type',
  13. 'url_media': '$url_media'
  14. }
  15. }
  16. }
  17. },
  18. { '$sort': { '_id': 1 } },
  19. {
  20. '$project': {
  21. '_id': 1,
  22. 'day': 1
  23. }
  24. }
  25. ], function(err, result) {
  26. res.json(result);
  27. });
  28.  
  29. [{
  30. _id: "2016-04-22",
  31. day: [{
  32. id: "c571be034449bee845f2b43211",
  33. when: "2016-04-22T20:51:00.190Z",
  34. type: "picture",
  35. url_media: "my_photo_1.jpg"
  36. }]
  37. }, {
  38. _id: "2016-04-23",
  39. day: [{
  40. id: "c571be034449bee845f2b43222",
  41. when: "2016-04-23T20:50:00.190Z",
  42. type: "picture",
  43. url_media: "my_photo_2.jpg"
  44. }, {
  45. id: "c571be034449bee845f2b43233",
  46. when: "2016-04-23T20:51:00.190Z",
  47. type: "picture",
  48. url_media: "my_photo_3.jpg"
  49. }]
  50. }]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement