Created
October 16, 2014 10:58
-
-
Save henryoswald/7bec14e3a3cd548d05af to your computer and use it in GitHub Desktop.
group premium users by role
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 db, mongoConnectionString, mongojs, query; | |
mongojs = require("mongojs"); | |
var ObjectId = mongojs.ObjectId | |
var async = require("async") | |
var _ = require("underscore") | |
mongoConnectionString = "mongodb://127.0.0.1/sharelatex-production"; | |
db = mongojs.connect(mongoConnectionString, ["subscriptions", "users"]); | |
query = { | |
recurlySubscription_id: { | |
$exists: true | |
} | |
}; | |
db.subscriptions.find(query, { | |
admin_id: 1 | |
}, function(err, subscriptions) { | |
async.map(subscriptions, function(sub, cb){ | |
var userQuery = {_id:sub.admin_id} | |
db.users.findOne(userQuery, {email:1, role:1, institution:1}, cb) | |
}, function(err, results){ | |
results = _.groupBy(results, function(result){ | |
if(result){ | |
return result.role | |
} | |
}) | |
console.log(results) | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment