Pymongo update_one() issue with embedded documents

Hi @Michael_Redlich, welcome back again to our forums. We’ve restructured these slightly since your last visit.

In general, this question might be better asked in one of the forums related to the Drivers or to Working with Data topic.

That said, it looks like there might be a quick solution to your problem.

In terms of updating a single element in array, you should use dot notation which allows the updating of a specific field in an embedded document or position within an array in your document. Checkout the $set page in the MongoDB Manual -

Have you tried using dot notation and an update_one statement of the format “composition.mv”?

db.polymers.update_one({"_id": polymer_id},{"$set": {“composition.mw”: 15000}})

Welcome back and hope this helps - if you have any questions or feedback related to M220P we’d love to hear it here, in this topic of our forums.

Kindest regards,
Eoin