Browse Source

Moved functionality from oebbmongohandler.

ogert 4 years ago
parent
commit
c81f8eeadd
1 changed files with 2 additions and 17 deletions
  1. 2 17
      cdplib/db_handlers/MongodbHandler.py

+ 2 - 17
cdplib/db_handlers/MongodbHandler.py

@@ -242,23 +242,8 @@ class MongodbHandler:
             else:
                 self._database[collection_name].insert_many(data, ordered=ordered)
 
-        except Exception as error:
-            if len(data) > 1:
-
-                self._log.warning(('An error occured inserting {} documents into database: {} and collection: {}.').format(len(data), self._database_name, collection_name))
-                self._log.warning('This might be because one or more documents are invalid.') 
-                self._log.warning('We will try to insert the documents one-by-one and report which are invalid.')
-                self._log.warning(('Error: {}').format(error))
-                
-                for row in data:
-
-                    try:
-                        self._database[collection_name].insert_one(row)
-                    except Exception as error:
-                        pprint(row)
-                        self._log.warning(error)
-            else:
-                self._log.log_and_raise_error(('An error occured when trying to insert data into {}, {}. \nError: {}').format(self._database_name, collection_name, error))
+        except pymongo.errors.BulkWriteError as error:
+            pprint(error.details)
 
         self._log.info(('Data has been inserted into the {} collection').format(collection_name))