I am trying to update a document if it exists and insert if it does not exist in the collection. I am inserting pandas data frame records as documents into a collection based on _id . Inserting a new document works fine, but updating fields in the old document does not work.
bulk = pymongo.bulk.BulkOperationBuilder(pros_rides,ordered=False) for doc in bookings_df: bulk.find({ "_id": doc["_id"] }).upsert().update({ "$setOnInsert": doc }) response = bulk.execute()
What am I missing?
, ; "$ setOnInsert" , , . , , , .
- :
bulk = pros_rides.initialize_unordered_bulk_op() for doc in books_df: bulk.find({'_id': doc['_id']}).upsert().replace_one(doc) bulk.execute()
Source: https://habr.com/ru/post/1660063/More articles:Search with dynamic field name in MongoDB - dynamicHow to transform a collection > to the list ? - javaScreen lock for ionic application - cordovaHow to display all products on one page in opencart? - phpCant see StrictMode information on logcat - violation of StrictMode policy on rotation screen - androidHow to display checkboxes instead of boolean in vaadin grid? - vaadinHow to do DOM manipulation in Angular components? - angularReset or Clear BootStrap authentication messages when we open and close the popup - twitter-bootstrapNSButton custom drawing ruined text rendering - cocoaSpring Download: use database and application.properties to configure - javaAll Articles