Skip to content

Instantly share code, notes, and snippets.

@nicolasembleton
Last active April 8, 2018 02:02
Show Gist options
  • Save nicolasembleton/10c0def71d0a25fb213d to your computer and use it in GitHub Desktop.
Save nicolasembleton/10c0def71d0a25fb213d to your computer and use it in GitHub Desktop.

Revisions

  1. nicolasembleton renamed this gist Nov 20, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. nicolasembleton created this gist Nov 20, 2014.
    8 changes: 8 additions & 0 deletions Find duplicates in Mongo
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    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}}})
    14 changes: 14 additions & 0 deletions Find duplicates in an Array - embedded object.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    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}})