Skip to content

Instantly share code, notes, and snippets.

@lorgio
Created April 11, 2014 17:27
Show Gist options
  • Select an option

  • Save lorgio/10486067 to your computer and use it in GitHub Desktop.

Select an option

Save lorgio/10486067 to your computer and use it in GitHub Desktop.
var values = []
var map = function() {
emit(key, value);
};
var emit = function(key,value){
// print("key: "+ tojsononeline(key) +" value: "+ tojsononeline(value));
output = {"_id": key, value: value}
print(output)
values.push(value)
}
var myCursor = db.events.find( { created_at: {$gt: ISODate("2014-03-03T00:00:09.043Z")}})
while (myCursor.hasNext()) {
var doc = myCursor.next();
map.apply(doc)
}
var reduce = function(key, values) {
var reducedValue = {key: key, values: null};
values.forEach(function(value) {
// put your reduce code in here
// reducedValue.values = something
});
return reducedValue;
};
reduce('mykey', values)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment