Return all documents that have just been entered into the collection.
I have a try block that gives me via insert_many documents in the collection. Now I would like to return only the documents in a var that have just been entered via insert_many. I need a specific field from all documents to make changes in another DB and Collection.
Here is my code block
try:
res = myCollection.insert_many(pickle_raw_new, ordered=False)
last_inserted_ids = res.inserted_ids
except pymongo.errors.BulkWriteError as e:
pass
finally:
#DocCOM: prüfe ob
#DocCOM: zähle die Dokumente der Collection colNAME und speicher Sie in der VAR count_after_insert
count_after_insert = myDB.get_collection("colNAME").estimated_document_count()
#DocCOM: subtrahiere die count_after_insert von count_before_insert und speicher das ergebnis in der VAR count_result
count_result = count_after_insert - count_before_insert
#DocCOM: prüfe ob die VAR count_before_insert und VAR count_after_insert ungleich sind, wenn JA dann printe count_result
#DocCOM: wenn NEIN dann printe Nachricht
if count_before_insert != count_after_insert:
print("Es wurden", count_result, "Datensätze der Collection hinzugefügt")
else:
print("Es wurden keine Datensätze hinzugefügt")