Skip to content

Instantly share code, notes, and snippets.

@nicolasembleton
Last active April 8, 2018 02:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nicolasembleton/10c0def71d0a25fb213d to your computer and use it in GitHub Desktop.
Save nicolasembleton/10c0def71d0a25fb213d to your computer and use it in GitHub Desktop.
MongoDB Queries
m = function () {
if(this.Model === 1) { // business logic specific, to remove if not need (allows to filter un-wanted values / keys)
for(var i in this.embed) {
key = i; // the key to look dupes for
value = 1; // cnt
emit(key, value);
}
}
}
r = function (key, values) {
return Array.sum(values);
}
db.MediaPlan.mapReduce(m, r, {out: {inline: 1}})
m = function () {
emit(this.ID, 1);
}
r = function (k, vals) {
return Array.sum(vals);
}
db.Vehicle.mapReduce(m, r, {out: {inline: 1}, query: {value: {$gt: 1}}})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment