Skip to content

Instantly share code, notes, and snippets.

@matheusdavidson
Created August 29, 2015 02:34
Show Gist options
  • Select an option

  • Save matheusdavidson/680a09f3e10963167a2b to your computer and use it in GitHub Desktop.

Select an option

Save matheusdavidson/680a09f3e10963167a2b to your computer and use it in GitHub Desktop.
var query = {
$match: {
"created": {
$gte: ISODate("2015-08-25T12:15:14-03:00")
}
}
}
var group = {
$group: {
_id: {
day: "$dayOfMonth"
},
day: {
$first: "$dayOfMonth"
},
"status_aguardando_pagamento": {
"$sum": { "$cond": [
{ "$eq": [ "$status", 0 ] },
1,
0
]}
},
"status_pago": {
"$sum": { "$cond": [
{ "$eq": [ "$status", 1 ] },
1,
0
]}
},
count: {
$sum: 1
}
}
}
var project = {
$project: {
"status": 1,
"items": "$items",
"year": {
$year: "$created"
},
"month": {
$month: "$created"
},
"dayOfMonth": {
$dayOfMonth: "$created"
},
"created": "$created"
}
}
db.getCollection('orders').aggregate([
{ $unwind: '$items' },
{ $unwind: '$items.insc' },
query,
project,
group
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment