Created
August 29, 2015 02:34
-
-
Save matheusdavidson/680a09f3e10963167a2b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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