title: MongoDB map/reduce, forEach is not a function?
body: <p>I am creating a Map function in MongoDB that have a problem as soon as I use forEach() on an array.</p>
  
  <p>This is how a user might look like:</p>
  
  <pre><code>"channels" : [
      "Channel 1",
      "Channel 2",
  ],
  "user_id" : "somehash"
  </code></pre>
  
  <p>This is my map function that is causing error:</p>
  
  <pre><code>var map = function() {
      if(this.channels &amp;&amp; this.user_id) {
  
          var user_id = this.user_id;
  
          this.channels.forEach(function(z, user_id) {
              emit(z, {user: user_id});
          });
      }
  }
  </code></pre>
  
  <p>When I am running my Map/Reduce in mongo I use the following command and I get also the following error:</p>
  
  <pre><code>&gt; db.users.mapReduce(map, reduce, {out : "myoutput" });
  Wed Aug  1 12:48:11 uncaught exception: map reduce failed:{
      "assertion" : "map invoke failed: JS Error: TypeError: this.channels.forEach is not a function nofile_b:3",
      "assertionCode" : 9014,
      "errmsg" : "db assertion failure",
      "ok" : 0
  }
  </code></pre>
  
  <p>I've tried some different approaches and none seem to work, this might be an easy problem but I can't see where I do it wrong.</p>
  
  <p>Would be glad to get some help on this issue.</p>
  
  <p>Thanks!</p>