use a pymongo bulk upsert operation to prevent data loss