Update gem counting script

This commit is contained in:
Matt Lott 2014-12-16 14:16:21 -08:00
parent 426424103a
commit d68746a922

View file

@ -1,11 +1,31 @@
// Print out gem counts bucketed by day and amount
// NOTE: created is a string and not an ISODate in the database
var match={
// Usage:
// mongo <address>:<port>/<database> <script file> -u <username> -p <password>
// Usage restricted to HoC Dates:
// mongo <address>:<port>/<database> -eval "var startDate='2014-12-08T00:00:00.000Z', endDate='2014-12-14T00:00:00.000Z';" <script file> -u <username> -p <password>
var match = null;
if (typeof startDate !== "undefined" && startDate !== null && typeof endDate !== "undefined" && endDate !== null) {
print("Using dates " + startDate + " to " + endDate);
match={
"$match" : {
"stripe.subscriptionID" : { "$exists" : false }
$and : [
{"created": { $gte: startDate}},
{"created": { $lt: endDate}},
{"stripe.subscriptionID" : { "$exists" : false }}
]
}
};
};
} else {
print("No date range specified.");
match={
"$match" : {"stripe.subscriptionID" : { "$exists" : false }}
};
}
var proj0 = {"$project": {
"amount": 1,
"created": { "$concat": [{"$substr" : ["$created", 0, 4]}, "-", {"$substr" : ["$created", 5, 2]}, "-", {"$substr" : ["$created", 8, 2]}]}
@ -22,5 +42,10 @@ var group={"$group" : {
}
}
};
var sort = {$sort: { "_id.d" : -1}};
db.payments.aggregate(match, proj0, group, sort).result.forEach( function (myDoc) { print({day: myDoc._id.d, amount: myDoc._id.m, count: myDoc.count}) })
var cursor = db.payments.aggregate(match, proj0, group, sort);
while (cursor.hasNext()) {
var doc = cursor.next();
print(doc._id.d + "\t" + doc._id.m + "\t" + doc.count);
}