Hello @Shanka_Somasiri, welcome to the MongoDB community forum.
You cannot assign a document field’s (totalQuantity) value in an update operation like that - hence the error. But, you can use the Updates with Aggregation Pipeline to do such an update using the document field’s value.
Note that this feature is supported only with MongoDB v4.2 or newer.