I import data from MongoDB to Pandas which I use to work with the data. Once the data has been changed in Pandas I want to update the DB which gives me the following error:
TypeError: 'Collection' object is not callable. If you meant to call the 'initialize_unordered_bulk_op' method on a 'Collection' object it is failing because no such method exists.
Not sure if I´m missing an import or if something else is wrong here. Is there a better solution to update data in bulk?
I use unordered-bulk-write-operations My Dataframe looks kinda like this:
_id, CHANNELNAME, USERNAME, DATETIME,
62fbd1ce819cb9e664961463, s, bf, 2022-01-01
62fbd1ce819cb9e664961463, d, bd, 2022-01-01
62fbd1ce819cb9e664961463, f, bs, 2022-01-01
I use this code to update the DB
date_selected = df.loc[df[search_column].between(start_date, end_date, inclusive=True)]
bulk_update = collection.initialize_unordered_bulk_op()
for index, row in date_selected.iterrows():
_id=row['_id']
new_value=row['CHANNELNAME']
bulk_update.find({'_id':_id}).update_one({'$set':{'CHANNELNAME':new_value}})
bulk_update.execute()