I've documents with the following structure:
> db.orders.find().limit(1).pretty()
{
"_id" : ObjectId("5846bf0e141be215b814f64a"),
"date_add" : ISODate("2016-10-10T11:55:24Z"),
"associations" : {
"order_rows" : [
{
"product_id" : "31",
"product_quantity" : "1",
},
{
"product_id" : "133",
"product_quantity" : "1",
}
]
},
}
while I was able to change the "date_add" field from String to ISODate with the help of the already answered questions on stackoverflow I'm stuck with:
How to change the field type of "product_quantity" to Integer?
I've tried the following in the mongo shell:
db.orders.find().forEach(function(x){
x.associations.order_rows.product_quantity = new NumberInt(x.associations.order_rows.product_quantity);
db.orders.save(x);
});
I then tried to use PyMongo and while I was able to extract the document and use the dictionary methods and a for loop to iterate over the list and change the value, I've no idea how to update the document back in the database.
A Solution in the mongo shell or python would be of tremendous help.
Thank you for your time and effort!