Add script to find active subscribers by country

This commit is contained in:
Nick Winter 2016-01-11 09:50:44 -08:00
parent 150e517c73
commit 01b181ee43
2 changed files with 23 additions and 0 deletions
scripts/analytics/mongodb/queries
server/users

View file

@ -0,0 +1,22 @@
// Print out subscribers by special country (China, Brazil)
// Usage:
// mongo <address>:<port>/<database> <script file> -u <username> -p <password>
var countries = ['brazil', 'china'];
countries.forEach(function(country) {
print('---' + country.toUpperCase() + '---');
var cursor = db.users.find({country: country, stripe: {$exists: true}}, {email: 1, country: 1, stripe: 1, name: 1});
var users = [];
var inactiveUsers = [];
while (cursor.hasNext()) {
var user = cursor.next();
if (!user.stripe.planID) {
inactiveUsers.push(user);
continue;
}
users.push(user);
print([user._id, user.country, user.email, user.name, JSON.stringify(user.stripe, null, 0)].join('\t'));
}
print('Had', users.length, 'active subscribers and', inactiveUsers.length, 'possible former subscribers in', country, '\n');
});

View file

@ -31,6 +31,7 @@ UserSchema.index({'slug': 1}, {name: 'slug index', sparse: true, unique: true})
UserSchema.index({'stripe.subscriptionID': 1}, {unique: true, sparse: true})
UserSchema.index({'siteref': 1}, {name: 'siteref index', sparse: true})
UserSchema.index({'schoolName': 1}, {name: 'schoolName index', sparse: true})
UserSchema.index({'country': 1}, {name: 'country index', sparse: true})
UserSchema.post('init', ->
@set('anonymous', false) if @get('email')