We have made a change in our data model and we would like to apply it to all documents in one of our collections:
{
"id":60,
"measurement":{
"steps":1274.0
},
"date":"2012-05-15T00:00:00Z"
}
to:
{
"id":60,
"measurement":{
"distance":{
"steps":1274.0}
},
"date":"2012-05-15T00:00:00Z"
}
Essentially, we want to further nest the field steps, placing it under the distance field.
As for measurement.step, we would like to convert measurement.miles to measurement.distance.miles and measurement.minutes to measurement.time.minutes.
Any thoughts and/or suggestions would be appreciated.
Assuming you’re asking how to script the schema change, which wasn’t quite clear in the question: I would do something like this, unless you have more cases for the document structure, or mixed cases:
You could pretty easily do the equivalent in the language/driver of your choice to ensure types, but it is probably faster to do in the shell. Hope it helps.