title: MongoDB generating same ID between inserts
body: <p>I am using pymongo and I am trying to insert dicts into mongodb database. My dictionaries look like this</p>
  
  <pre><code>{
      "name" : "abc",
      "Jobs" : [
          {
              "position" : "Systems Engineer (Data Analyst)",
              "time" : [
                  "October 2014",
                  "May 2015"
              ],
              "is_current" : 1,
              "location" : "xyz",
              "organization" : "xyz"
          },
          {
              "position" : "Systems Engineer (MDM Support Lead)",
              "time" : [
                  "January 2014",
                  "October 2014"
              ],
              "is_current" : 1,
              "location" : "xxx",
              "organization" : "xxx"
          },
          {
              "position" : "Asst. Systems Engineer (ETL Support Executive)",
              "time" : [
                  "May 2012",
                  "December 2013"
              ],
              "is_current" : 1,
              "location" : "zzz",
              "organization" : "xzx"
          },
      ],
      "location" : "Buffalo, New York",
      "education" : [
          {
              "school" : "State University of New York at Buffalo - School of Management",
              "major" : "Management Information Systems, General",
              "degree" : "Master of Science (MS), "
          },
          {
              "school" : "Rajiv Gandhi Prodyogiki Vishwavidyalaya",
              "major" : "Electrical and Electronics Engineering",
              "degree" : "Bachelor of Engineering (B.E.), "
          }
      ],
      "id" : "abc123",
      "profile_link" : "example.com",
      "html_source" : "&lt;html&gt; some_source_code &lt;/html&gt;"
  }
  </code></pre>
  
  <p>I am getting this error:</p>
  
  <blockquote>
    <p>pymongo.errors.DuplicateKeyError: E11000 duplicate key error index:
    Linkedin_DB.employee_info.$<em>id</em> dup key: { :
    ObjectId('56b64f6071c54604f02510a8') }</p>
  </blockquote>
  
  <p>When I run my program 1st document gets inserted properly but when I insert the second document I get this error. When I start my script again the document which was not inserted because of this error get inserted properly and error comes for next document and this continues.</p>
  
  <p>Clearly mognodb is using the same objecID during two inserts. I don't understand why mongodb is failing to generate a unique ID for new documents. </p>
  
  <p>My code to save passed data:</p>
  
  <pre><code>class Mongosave:
      """
          Pass collection_name and dict data
          This module stores the passed dict in collection
      """
  
      def __init__(self):
          self.connection = pymongo.MongoClient()
          self.db = self.connection['Linkedin_DB']
  
      def _exists(self, id):
          #To check if user alredy exists
          return True if list(self.collection.find({'id': id})) else False
  
      def save(self, collection_name, data):
          self.collection = self.db[collection_name]
          if not self._exists(data['id']):
              print (data['id'])
              self.collection.insert(data)
          else:
              self.collection.update({'id':data['id']}, {"$set": data})
  </code></pre>
  
  <p>I can figure out why this is happening. Any help is appreciated.</p>