title: When saving scraped items to Mongodb using Scrapy.Pipeline, an error came up
body: <p>I've been struggling with Scrapy and Mongodb for quite a while. I successfully crawled data from <a href="http://antispam.imp.ch/spamlist" rel="nofollow noreferrer">http://antispam.imp.ch/spamlist</a> but when I finished Pipeline, a <code>KeyError: 'AntispamItem does not support field: _id'</code> just came up.
    I'm new to Python and Mongodb, and it seems that nothing wrong of my codes can be concluded from the error log..and I've already tried every solution from Google..I thought when inserting to mongodb, ids are automatically generated..but it seems not the case.I'd be really grateful if someone could tell me how to tackle this problem.
    Following is Pipelines.py:</p>
  
  <pre><code>import pymongo
  from scrapy.conf import settings
  class AntispamPipeline(object):
      def __init__(self):
          connection=pymongo.MongoClient('localhost',27017)
          db=connection['threat_ip']
          self.collection=db['data_center_test']
  
      def process_item(self, item, spider):
          self.collection.insert(item)
          return item
  </code></pre>
  
  <p>Following is the spider and error log</p>
  
  <pre><code>import re
  import scrapy
  from antispam.items import AntispamItem
  class Antispam_Spider(scrapy.Spider):
      name='antispam'
      start_urls=['http://antispam.imp.ch/spamlist']
      def parse(self, response):
          content=response.body
          ip_name=re.findall('\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}',content)
          content_list=content.split('\t')
          content_data=[]
          for i in range(0,len(content_list)-1):
              if content_list[i] in ip_name:
                  dic={}
                  dic['name']=content_list[i]
                  dic['time']=content_list[i+2]
                  content_data.append(dic)
              else:
                  pass
  
          for dic in content_data:
              item=AntispamItem()
              item['name']=dic['name']
              item['time']=dic['time']
              item['type']='Spam Sources'
              yield item
  
  
  
  
  KeyError: 'AntispamItem does not support field: _id'
  2017-01-10 15:59:02 [scrapy.core.scraper] ERROR: Error processing {'name': '223.230.65.17',
   'time': 'Mon Jan  9 01:07:38 2017',
   'type': 'Spam Sources'}
  Traceback (most recent call last):
    File "c:\python27\lib\site-packages\twisted\internet\defer.py", line 651, in _runCallbacks
      current.result = callback(current.result, *args, **kw)
    File "V:\work\antispam\antispam\pipelines.py", line 16, in process_item
      self.collection.insert(item)
    File "c:\python27\lib\site-packages\pymongo\collection.py", line 2469, in insert
      check_keys, manipulate, write_concern)
    File "c:\python27\lib\site-packages\pymongo\collection.py", line 562, in _insert
      check_keys, manipulate, write_concern, op_id, bypass_doc_val)
    File "c:\python27\lib\site-packages\pymongo\collection.py", line 524, in _insert_one
      doc['_id'] = ObjectId()
    File "c:\python27\lib\site-packages\scrapy\item.py", line 63, in __setitem__
      (self.__class__.__name__, key))
  KeyError: 'AntispamItem does not support field: _id'
  </code></pre>
  
  <p>In the official doc of MongoDB, I saw <code>"If the document does not specify an _id field, then MongoDB will add the _id field and assign a unique ObjectId for the document before inserting."</code> So does anyone could tell me what happened?</p>