开发者社区> 问答> 正文

scrapy+mongodb 插入文档的数目不够的原因?

我使用mongo储存scrapy爬下来的页面数据,在管道中为同时向db和txt中写入结果,结果发现txt有8000多条记录,而db中count才831条,百思不得其解。后来将db中数据导出,发现似乎是item['content'](文章内容)字段内容比较多的就没有成功插入db。后来想了下,似乎是db的单个文档大小有限制,但是这些文本写到txt最多不过几十kb,这到底是什么问题?
附上管道process_item的代码
`def process_item(self, item, spider):
self.file1.write(item['url']+'n'+item['content']+"n")
word_list = list(jieba.cut(item['content']))
for word in word_list:
if len(word)>1:
self.file.write(word+'/')
self.file.write('n1111111111111111111n')
self.collection.insert(dict(item))
log.msg('Item written to MongoDB database %s/%s' % (self.db, self.col),
level=log.DEBUG, spider=spider)
return item`

展开
收起
落地花开啦 2016-02-27 16:20:41 4405 0
1 条回答
写回答
取消 提交回答
  • 对于failIndexKeyTooLong ERROR在shell中使用如下命令可以修改活动中的db设置db.getSiblingDB('admin').runCommand( { setParameter: 1, failIndexKeyTooLong: false } )

    2019-07-17 18:49:02
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Data as a Service - 数据即服务 -- MongoDB⾼级应⽤模式 立即下载
MongoDB多数据中心的方案选型之路 立即下载
饿了么高级架构师陈东明:MongoDB是如何逐步提高可靠性的 立即下载