mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-04-27 06:23:41 -04:00
Add script to find active subscribers by country
This commit is contained in:
parent
150e517c73
commit
01b181ee43
2 changed files with 23 additions and 0 deletions
22
scripts/analytics/mongodb/queries/subscribersByCountry.js
Normal file
22
scripts/analytics/mongodb/queries/subscribersByCountry.js
Normal 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');
|
||||
});
|
|
@ -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')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue