Two ways to update docs in cursor objects with pymongo

I have a collection with:

name    weight    amount
—————————————-
apple     2               3
banana  2               5
pear       2               5

I want add a column about the total price, which is equal to weight * amount

name    weight    amount    total
—————————————————-
apple     2               3              6
banana  2               5             10
pear       2               5            10

Method 1: collection.find() + update_one()

Method 2: collection.aggregate() with $project, $multiply and $out

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.