title: Mongojs: Ignoring Duplicate Objects Insertion
body: <p>I have this Node.js application that it gets a large sum of JSON data with unique ids and then inserts them into a MongoDB using Mongojs.</p>
  
  <p>The problem is that in this large array of data, there might be some duplicate documents! so when using Mongojs to insert these data, it returns an error <code>E11000 duplicate key error</code> and wouldn't continue the insertion.</p>
  
  <p>So what I'm looking for is something like the <code>continueOnError/keepGoing</code> option of native Mongo. It would ignore duplicates and continue the <code>insert</code>.<br>
  <a href="http://mongodb.github.io/node-mongodb-native/api-generated/collection.html#insert" rel="nofollow">http://mongodb.github.io/node-mongodb-native/api-generated/collection.html#insert</a>   </p>
  
  <p>This is my code if it helps:    </p>
  
  <pre><code>var mongojs = require('mongojs'),
  dburl = process.env.MONGOHQ_URL || 'mongodb://localhost/test',
  db = mongojs(dburl, ['concerts']);
  
  function insertData(data) {
  db.concerts.insert(data, {keepGoing: true, safe: true}, function(err, docs){
      console.log('err: ' + err + '  docs:' + docs);
      if(!err) console.log('data inserted successfully!\n');
  });
  }
  
  exports.insertData = insertData;
  </code></pre>
  
  <p>Here in this code I have set option to true, but it still does not work (the same error).<br>
  Is there anyway that I can do this with Mongojs or do I have to use native-mongo?</p>
  
  <p>Thanks in advance.</p>