无法在mongodb中执行bulk_write操作

时间:2018-12-17 09:32:35

标签: mongodb

我正在尝试使用bulk_write将集合“ csgdb_master”中的所有文档写入“ csgdb_follewer”中,但操作失败。请注意,会有一些冲突。我是由于冲突而陷入错误中还是存在一些代码问题?

我的代码-

from pymongo import MongoClient
from pymongo import InsertOne
# pprint library is used to make the output look more pretty
#from pprint import pprint
# connect to MongoDB, change the << MONGODB URL >> to reflect your own 
connection string
#client = MongoClient("mongodb://127.0.39.1:27018", ssl=True, 
ssl_ca_certs='/opt/ampli/cfg/ssl/.ca.crt')
client = MongoClient("mongodb://127.0.0.1:27017")
db=client.csgdb_master
db1=client.csgdb_follower
#collection=db.buckets
#ids = {}
#ids=db.buckets.distinct("_id")
#print ids
cursor_excess_new = (db.buckets.find().sort([("_id", 1)]).limit(20))
queries = [InsertOne(doc) for doc in cursor_excess_new]
db1.buckets.bulk_write(queries)

错误-

Traceback (most recent call last):
  File "mongodbtest.py", line 16, in <module>
    db1.buckets.bulk_write(queries)
  File "/home/root1/Debashish/tekken_tests/venv/local/lib/python2.7/site-packages/pymongo/collection.py", line 491, in bulk_write
    bulk_api_result = blk.execute(self.write_concern.document, session)
  File "/home/root1/Debashish/tekken_tests/venv/local/lib/python2.7/site-packages/pymongo/bulk.py", line 432, in execute
    return self.execute_command(generator, write_concern, session)
  File "/home/root1/Debashish/tekken_tests/venv/local/lib/python2.7/site-packages/pymongo/bulk.py", line 329, in execute_command
    raise BulkWriteError(full_result)
pymongo.errors.BulkWriteError: batch op errors occurred

有帮助吗?

0 个答案:

没有答案