title: MongoDB insert without duplicates
body: <p>Right now I am running mongodb and I just realized, I am inserting into collections and I am not sure if I am preventing duplicates. Here is how I am inserting:</p>
  
  <pre><code>function insertCompanies(companyID, companyURL, companyAppID) {
      MongoClient.connect(url, function(err, db) {
          if (err) {
              console.log(err);
          } else {
              console.log("We are connected");
          }
  
          var collection = db.collection('Companies');
          var company = {
              "companyProfileID": companyID,
              "url": companyURL,
              "appID": companyAppID
          };
          collection.insert(company, function(err, result) {
              if (err) {
                  console.log(err);
              } else {
                  console.log(result);
              }
          });
          db.close();
      });
  }
  </code></pre>
  
  <p>I am using NodeJS. When a user calls the <code>insertCompanies</code> method, if the company already exists (via <code>companyID</code> or <code>URL</code>), it seems like the collection allows duplicates.</p>
  
  <p>Is there a different insert function that prevents duplicates? I looked around and could not find a straight forward solution tailored to me.</p>