codecombat/scripts/analytics/mongodb/queries/SubscriptionsPerDay.js

39 lines
1,009 B
JavaScript
Raw Normal View History

2014-12-15 16:36:45 -05:00
// Print out subscription counts bucketed by day and amount
// NOTE: created is a string and not an ISODate in the database
2015-03-26 17:10:59 -04:00
// Usage:
// mongo <address>:<port>/coco <script file> -u <username> -p <password>
// TODO: does not differeniate between new and recurring payments
2014-12-15 16:36:45 -05:00
var match={
"$match" : {
"stripe.subscriptionID" : { "$exists" : true }
}
};
var proj0 = {"$project": {
"amount": 1,
"created": {"$substr" : ["$created", 0, 10]}
2014-12-15 16:36:45 -05:00
}
};
var group={"$group" : {
"_id" : {
"m" : "$amount",
"d" : "$created"
},
"count" : {
"$sum" : 1
}
}
};
var sort = {$sort: { "_id.d" : -1}};
//db.payments.aggregate(match, proj0, proj1, proj2, group)
2015-03-26 17:10:59 -04:00
var cursor = db.payments.aggregate(match, proj0, group, sort);
while (cursor.hasNext()) {
var myDoc = cursor.next();
print(myDoc._id.d, myDoc._id.m, myDoc.count);
}
//db.payments.aggregate(match, proj0, group, sort)
2014-12-15 16:36:45 -05:00
//db.payments.aggregate(match)
2015-03-26 17:10:59 -04:00
//db.payments.find()