Skip to content

Instantly share code, notes, and snippets.

@howarddierking
Created April 28, 2014 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save howarddierking/11384765 to your computer and use it in GitHub Desktop.
Save howarddierking/11384765 to your computer and use it in GitHub Desktop.
var mapByOrgID = function(){
var orgID = this.OrgID;
if(orgID)
emit(orgID, { ecosystem: this.ecosystem });
};
var reduceEcosystems = function(key, values){
var ret = {
orgID: key,
ecosystems: []
};
_.each(values, function(item){
if(item.ecosystem && !_.contains(ret.ecosystems, item.ecosystem))
ret.ecosystems.push(item.ecosystem);
});
return ret;
};
staging.init(function(err, stagingDb){
var mrOptions = {
query: {
OrgID: { $exists: true, $ne: null }
},
out: {
reduce: reducedOrganizationsCollection
}
};
stagingDb.mongoClient.collection(organizationsCollection).mapReduce(mapByOrgID,
reduceEcosystems, mrOptions, function(err, collection){
console.info(util.format('Finished reducing organizations to collection %s', reducedOrganizationsCollection));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment