title: pymongo getting E11000 duplicate key error index pymongo error
body: <p>So a little background, I've worked with MongoDB before in node.js with mongoose.js. And now I decided to try out to work with python and pymongo. But when I try to insert a document into my collection I just get an error off:</p>
  
  <pre><code>pymongo.errors.DuplicateKeyError: E11000 duplicate key error index: database.emails.$email_1 dup key: { : "mail@example.com" }
  </code></pre>
  
  <p>I have been looking around on the internet for a solution both in python but also in other languages. It might very well be that sense iv only used mongoose.js to talk to mongo before and that I might not fully grasp the basics off MongoDB.</p>
  
  <p>From model.py</p>
  
  <pre><code>from pymongo import MongoClient
  
  class Model(object):
      client = MongoClient()
      db = client["database"]
      collection_name = ""
  
      def __init__(self):
          self.collection = self.db[self.collection_name]
  
      def save(self, data):
          self.collection.insert_one(data)
  </code></pre>
  
  <p>From Post.py</p>
  
  <pre><code>from model import Model
  
  class Post(Model):
  
      collection_name = "emails"
  
      def __init__(self):
          super(Post, self).__init__()
  </code></pre>
  
  <p>And in app.py I just do </p>
  
  <pre><code>from models.Post import Post
  
  post = Post()
  post.save({"email":"mail@example.com", "name":"bob"})
  </code></pre>
  
  <p>When there is no document in the database it inserts fine. But if I try to insert the same again I get the DuplicateKeyError. It is as if MongoDB expects all the fields to have a unique or am I misunderstanding the processes?</p>
  
  <p>Im using the latest version of pymongo. </p>