gpt4 book ai didi

MongoDB批量写入错误

转载 作者:IT老高 更新时间:2023-10-28 13:08:08 26 4
gpt4 key购买 nike

我正在执行批量写入

bulk = new_packets.initialize_ordered_bulk_op()

bulk.insert(数据包)

输出 = bulk.execute()

并收到一个错误,我将其解释为该数据包不是字典。但是,我确实知道这是一个字典。可能是什么问题?

这是错误:

    BulkWriteError                            Traceback (most recent call last)
<ipython-input-311-93f16dce5714> in <module>()
2
3 bulk.insert(packet)
----> 4 output = bulk.execute()

C:\Users\e306654\AppData\Local\Continuum\Anaconda\lib\site-packages\pymongo\bulk.pyc in execute(self, write_concern)
583 if write_concern and not isinstance(write_concern, dict):
584 raise TypeError('write_concern must be an instance of dict')
--> 585 return self.__bulk.execute(write_concern)

C:\Users\e306654\AppData\Local\Continuum\Anaconda\lib\site-packages\pymongo\bulk.pyc in execute(self, write_concern)
429 self.execute_no_results(generator)
430 elif client.max_wire_version > 1:
--> 431 return self.execute_command(generator, write_concern)
432 else:
433 return self.execute_legacy(generator, write_concern)

C:\Users\e306654\AppData\Local\Continuum\Anaconda\lib\site-packages\pymongo\bulk.pyc in execute_command(self, generator, write_concern)
296 full_result['writeErrors'].sort(
297 key=lambda error: error['index'])
--> 298 raise BulkWriteError(full_result)
299 return full_result
300

BulkWriteError: batch op errors occurred

最佳答案

可能有很多原因...
最好的方法是您尝试...捕获...异常并检查错误

from pymongo.errors import BulkWriteError
try:
bulk.execute()
except BulkWriteError as bwe:
print(bwe.details)
#you can also take this component and do more analysis
#werrors = bwe.details['writeErrors']
raise

关于MongoDB批量写入错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30355790/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com