3
votes

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!

1
Have you looked at the command line tools and found them wanting? docs.mongodb.org/manual/core/import-exporthughdbrown
I think the question you are trying to ask is if there is a bulk save in Mongo, not necessarily for pymongo specifically?Chris Dutrow

1 Answers

1
votes

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