我正在尝试在mongodb集合中大容量插入一些文档。在
我对我收藏的链接字段施加了一个独特的约束。在
bulkUrls = db.urls.initialize_ordered_bulk_op()
for info in links:
info = urljoin(url['link'], info)
if '#' in info:
info = info[:info.index('#')]
if(validateUrl(info)):
bulkUrls.insert({'link' : info, 'last_processed' : 0, 'created_at' : time(), 'page_id' : str(inserted_id), 'opened' : False})
bulkUrls.execute()
附件是我的python代码。 {I}只想在另一个文档集合中插入同一个文档。在
我们将感谢您的帮助。在
如果不必使用有序批量,则可以使用无序批量操作。在
无序的大容量写入操作被批处理并以任意顺序发送到服务器,在那里它们可以并行执行。尝试执行所有操作后,将报告发生的任何错误。 来自pymongo documentation
所以只需使用:
如果您坚持使用ordered bulk,可以将写入问题设置为0。在
根据上面相同的链接
^{pr2}$注意:这将禁用写确认,这意味着您将不知道写入操作是否成功(“不推荐”)。在
相关问题 更多 >
编程相关推荐