PyMongo – Upsert many documents [duplicate]

7 views
0

This question already has an answer here:

I am working with python and mongodb, using PyMongo.

I have a list of items that I want to save in the database. In this list – there might be objects that already exist in database and objects that do not exist.

I want to perform one operation that will upsert all this list in the database. That is – it will update objects that already exist and insert objects that do not exist.

What’s the best way to do it in PyMongo?