Skip to content

Instantly share code, notes, and snippets.

@noirbizarre
Last active August 4, 2017 16:15
Show Gist options
  • Save noirbizarre/2ad455bb9e1013268cb47fc7e73bcaff to your computer and use it in GitHub Desktop.
Save noirbizarre/2ad455bb9e1013268cb47fc7e73bcaff to your computer and use it in GitHub Desktop.
A Map-Reduce listing remaining dataset coverage zones with slashes in identifiers
/*
* List zones with slahes in identifiers with their occurence count
*/
function mapZonesWithSlahes() {
this.spatial.zones.forEach(function(zone) {
if (zone.indexOf('/') >= 0) {
emit(zone, 1);
}
});
}
function countOccurences(key, values) {
return Array.sum(values);
}
db.dataset.mapReduce(mapZonesWithSlahes, countOccurences, {
// See https://docs.mongodb.com/manual/reference/method/db.collection.mapReduce/#out-options
out: 'zones_with_slashes',
query: {'spatial.zones': {$exists: true}}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment