title: How to drop a collection with pymongo?
body: <p>I use <code>scarpy</code> to crawl data and save it to cloud hosting <code>mLab</code> successfully with MongoDB.</p>
  
  <p>My collection name is <code>recently</code> and data's count is 5.
  <a href="https://i.stack.imgur.com/OM4ot.png" rel="noreferrer"><img src="https://i.stack.imgur.com/OM4ot.png" alt="enter image description here"></a></p>
  
  <p>I want to crawl data again and update my collection <code>recently</code>, so i try to drop the collection and then insert.</p>
  
  <p>Here is my code pipelines.py:</p>
  
  <pre><code>from pymongo import MongoClient
  from scrapy.conf import settings
  
  class MongoDBPipeline(object):
  
      def __init__(self):
          connection = MongoClient(
              settings['MONGODB_SERVER'],
              settings['MONGODB_PORT'])
          db = connection[settings['MONGODB_DB']]
          # here is my collection name recently setting
          self.collection = db[settings['MONGODB_COLLECTION']]
  
      def process_item(self, item, spider):
          # try to drop my collection recently
          self.collection.drop()
          self.collection.insert(dict(item))
          return item
  </code></pre>
  
  <p>But when I run my spider, I see my collection <code>recently</code> count is 10 (It should be 5 that is what I want)
  <a href="https://i.stack.imgur.com/wPUPb.png" rel="noreferrer"><img src="https://i.stack.imgur.com/wPUPb.png" alt="enter image description here"></a></p>
  
  <p>I looking for some code that how to drop collection.
  It's just say db.[collection Name].drop()</p>
  
  <p>But its no working in my case when i try <code>self.collection.drop()</code> before <code>self.collection.insert(dict(item))</code></p>
  
  <p>Anyone can give me some suggestions what is wrong with my code ? </p>
  
  <p>That would be appreciated. Thanks in advance.</p>