Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- db.collection('checkpoint').aggregate
- [
- { '$match': {'id_journey': journey.id_journey} },
- { '$sort': { 'when': 1} },
- {
- '$group': {
- '_id': { $dateToString: { format: '%Y-%m-%d', date: '$when' } },
- 'day': {
- '$push': {
- 'id': '$id_checkpoint',
- 'when': '$when',
- 'type': '$type',
- 'url_media': '$url_media'
- }
- }
- }
- },
- { '$sort': { '_id': 1 } },
- {
- '$project': {
- '_id': 1,
- 'day': 1
- }
- }
- ], function(err, result) {
- res.json(result);
- });
- [{
- _id: "2016-04-22",
- day: [{
- id: "c571be034449bee845f2b43211",
- when: "2016-04-22T20:51:00.190Z",
- type: "picture",
- url_media: "my_photo_1.jpg"
- }]
- }, {
- _id: "2016-04-23",
- day: [{
- id: "c571be034449bee845f2b43222",
- when: "2016-04-23T20:50:00.190Z",
- type: "picture",
- url_media: "my_photo_2.jpg"
- }, {
- id: "c571be034449bee845f2b43233",
- when: "2016-04-23T20:51:00.190Z",
- type: "picture",
- url_media: "my_photo_3.jpg"
- }]
- }]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement