Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a pymongo (or another Python library) bulk-save?

I'm trying to write a function to do a bulk-save to a mongoDB using pymongo, is there a way of doing it? I've already tried using insert and it works for new records but it fails on duplicates. I need the same functionality that you get using save but with a collection of documents (it replaces an already added document with the same _id instead of failing).

Thanks in advance!

like image 671
Sergio Ayestarán Avatar asked Nov 30 '25 08:11

Sergio Ayestarán


1 Answers

you can use bulk insert with option w=0 (ex safe=False), but then you should do a check to see if all documents were actually inserted if this is important for you

like image 171
nickmilon Avatar answered Dec 01 '25 22:12

nickmilon