Update all documents in a collection based on a property which is under a dynamic field

Lets fix

first because it is needed anyway for the update.

The following aggregation pipeline should provide with a better way to

[
    { "$set" : {
        "_tmp.root" : { "$objectToArray" : "$$ROOT" }
    } } ,
    { "$match" : {
        "_tmp.root.v.rating" : ".80"
    } } ,
    { "$unset" : "_tmp" }
]

Much faster that downloading everything but still sub-optimal since you cannot use an index.

But since

there is no way to use an index.

Carefully read about the attribute pattern and get rid of these numbers as keys.

Now that we have a way to get only the documents to update, you are able to do, with a python loop, a sub-optimal bulk write with one updateOne operation for each _id that you have to update.

I still have to work on how to do it directly with aggregation but it needs some work. It will involve, I think, some $filter (to only keep v.rating:.80 from _tmp.root) , an $arrayToObject, a $mergeObject (to update $$ROOT) and then a $merge stage to commit the update. UGLY

Carefully read about the attribute pattern and get rid of these numbers as keys.