title: Implementing ensureIndex() to delete duplicate documents with pymongo
body: <p>I need to delete the duplicate entries based on unique values of field "X". It works fine in mongodb shell:</p>
  
  <pre><code>db.collection.ensureIndex({x' : 1},{unique: true, dropDups: true})
  </code></pre>
  
  <p>I want to run this using pymongo and the code I used is as follows:</p>
  
  <pre><code>import pymongo
  import mmh3
  
  conn = pymongo.MongoClient()
  db = conn['scrapy-mongodb']
  
  db.collection.ensure_index({'x' : 1}, {'$unique' : True, '$dropDups' : True})
  </code></pre>
  
  <p>This code throws: </p>
  
  <blockquote>
    <p>TypeError: if no direction is specified, key_or_list must be an
    instance of list</p>
  </blockquote>
  
  <p>Where did I go wrong?</p>