Skip to content

Instantly share code, notes, and snippets.

@alejandrobernardis
Created January 16, 2014 16:40
Show Gist options
  • Save alejandrobernardis/8458284 to your computer and use it in GitHub Desktop.
Save alejandrobernardis/8458284 to your computer and use it in GitHub Desktop.
MDB
op = db.devices.aggregate([{
$project: {
date: 1,
newDate: {
year: {
$year: '$created'
},
month: {
$month: '$created'
},
day: {
$dayOfMonth: '$created'
},
}
}
}, {
$group: {
_id: '$newDate',
total: {
$sum: 1
}
}
}, {
$sort: {
_id: -1
}
}, ]);
db.report.devices.insert(op.result);
op = db.devices.aggregate([{
$project: {
date: 1,
newDate: {
year: {
$year: '$created'
},
month: {
$month: '$created'
},
day: {
$dayOfMonth: '$created'
},
},
device: "$device"
}
}, {
$group: {
_id: {
date: '$newDate',
device: '$device'
},
total: {
$sum: 1
}
}
}, {
$sort: {
_id: -1
}
}, ]);
db.report.devicestypesbyday.insert(op.result);
op = db.devices.aggregate([{
$group: {
_id: '$device',
total: {
$sum: 1
}
}
}, {
$sort: {
_id: -1
}
}, ]);
db.report.devicestypes.insert(op.result);
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment