Home > Mobile >  Accessing PyMongo UpdateOne operation properties
Accessing PyMongo UpdateOne operation properties

Time:12-24

If I am receiving a list of prepared PyMongo UpdateOne operations (e.g. below)...

print(type(to_load[0]))
> <class 'pymongo.operations.UpdateOne'>

print(to_load[0])
> UpdateOne({'id': XXX}, {'$set': {'name': 'YYY'}}, True, None, None, None)

...is it possible to then extract information from these? For instance, if I want to get a list of all of the affected 'id' values [XXX, ...], is there something like the below (which does not work) that will work?

for record in to_load:
  print(record['filter'])

CodePudding user response:

You can access it with the _filter attribute, with the usual caveat that _ prefixed attributes are protected and subject to change without notice.

for record in to_load:
    print(record._filter)

Reference: examining the source code.

  • Related