I wanted to update a number of records in my mongodb collection, so I wanted to duplicate the field value to another field. Here is my code:
res = result_collection.update_many(filter = {'requestid' : { '$in': str_req_ids }},
update = {'$set': { 'original_requestid': '$requestid' }},
session = session
I was expecting that the field original_requestid
will be the value of the field of requestid
, but it seems the value saved is literally $requestid
instead. How to make sure that $requestid
here was parsed as a value from the collection instead of a literal string?
I saw there is some approach using this link, but I prefer to use the update_many
functionality rather than eval
code which may cause some issues later.