Mongodb sketch error

I am mass recording

bulk = new_packets.initialize_ordered_bulk_op()

bulk.insert(packet)

output = bulk.execute()

and get an error, which I interpret as meaning that the package is not a dict. However, I know this is a dictation. What could be the problem?

Here is the error:

  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 
+7
mongodb pymongo
source share
3 answers

There may be many reasons ...
the best you are trying to ... catch ... an exception and check for errors

 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 
+6
source share

You should check 2 things:

  • Duplicates if you define your own key.
  • Be able to manage custom types. In my case, I tried to pass a hash type object that could not be converted to a valid ID object, and this led me to the first point, and I felt in a vicious circle (I decide to convert myObject to string.

Insert one by one will give you an idea of ​​what is happening.

+5
source share

Well, the problem was that I was explicitly assigning _id, and it turned out that the string was over the 12-byte limit, mine is bad.

+2
source share

All Articles