Last active
December 20, 2015 13:39
-
-
Save stevenleeg/6141004 to your computer and use it in GitHub Desktop.
This file contains 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 MongoClient = require("mongodb").MongoClient; | |
MongoClient.connect(process.env.MONGO_URI, function(err, db) { | |
var users = db.collection("users"); | |
var places = db.collection("places"); | |
var one_done = 0; | |
function checkDone() { | |
if(one_done == 3) { | |
db.close(); | |
} else { | |
one_done += 1; | |
} | |
} | |
function reduce(key, values) { | |
var result = 0; | |
values.forEach(function(value) { | |
result += value; | |
}); | |
return result; | |
} | |
var options = { | |
out: {inline: 1}, | |
scope: { places: places, console: console } | |
} | |
/* | |
* Tags distributions | |
*/ | |
users.mapReduce(function() { | |
for(var i in this.bookmarks) { | |
var bookmark = this.bookmarks[i]; | |
// Notes | |
if(bookmark.tags == undefined) { | |
emit(0, 1); | |
break; | |
} | |
// Check to see if the tags are different than the place's | |
// SEGFAULT IS HERE (I think) | |
places.find({ _id: bookmark.place_id }); | |
emit(bookmark.tags.length, 1); | |
emit("1+", 1); | |
} | |
}, reduce, options, function(err, results) { | |
console.log("\n--- tags distribution --"); | |
console.log(err); | |
console.log(results); | |
checkDone(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment