title: Node.js mongodb bulk insert
body: <p>i'm kinda new to node.js and mongo and i'm having a little problem. I can't bulk insert documents into mongodb using ajax on client and nodejs/express on server. Here is my client code:</p>
  
  <pre><code>&lt;button class="btn&gt;Send&lt;/button&gt;
  data = {'test':'test1','test':'2','test':'test1','test':'test2','test':'test1','test':'test2'}
  
          $(".btn").click(function(){
              $.ajax({
                  url: 'http://localhost:8000/2',
                  type: 'post',
                  dataType: 'json',
                  data: data 
              });
          });
  </code></pre>
  
  <p>And here is my route handler in node:</p>
  
  <pre><code>app.post('/2', function(req, res){
  var docs = [];
   for(var i = 0; i &lt; 10000; i++) {
       docs[i] = req.body;
   }
  
   db.collection('test', function(err, collection){
      collection.insert(docs, function(err, result) {
          if (!err) {
              console.log(result);
              res.end();
          } else {
              throw err
          }
      })
   });
  </code></pre>
  
  <p>})</p>
  
  <p>I'm getting data nicely with console.log(docs), but my test collection is empty. What am i missing? Thanks</p>