Created
September 10, 2014 13:00
-
-
Save boxdot/7e42a24b018d70e0b1cb to your computer and use it in GitHub Desktop.
MapReduce of MongoDB puts the result in `values` field. Sometimes one wants the result to be a document and not a pair `(_id, values)`. The function below flattens the result of map_reduce.
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
function(table) { | |
db[table].find().forEach(function(x) { | |
var update = { $set: {}, $unset: { value: '' } } | |
for (var k in x.value) | |
update.$set[k] = x.value[k] | |
db[table].update({_id: x._id}, update) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment