0

I have this collection

> db.styles.find({"_id":"EP65"}).pretty();
{
    "__v" : 6,
    "_id" : "EP65",
    "colours" : {
        "GRYM" : [
            {
                "on_sale" : false,
                "size_code_id" : "XS",
                "sku" : "EP65-GRYM0"
            },
            {
                "on_sale" : false,
                "size_code_id" : "2XL",
                "sku" : "EP65-GRYM5"
            }
        ],
        "BLUT" : [
            {
                "on_sale" : false,
                "size_code_id" : "XS",
                "sku" : "EP65-BLUT0"
            },
            {
                "on_sale" : false,
                "size_code_id" : "X",
                "sku" : "EP65-BLUT1"

            }
        ]
    }
}

I would like to rename the "on_sale" to "visible", I have about 200 styles each of which has one or many colours.

So basically I want to loop through all the styles collection and for each colour.key rename the "on_sale" to "visible"

any advice is much appreciated

David says Reinstate Monica
  • 19,209
  • 22
  • 79
  • 122
khinester
  • 3,398
  • 9
  • 45
  • 88

1 Answers1

0

As mentioned in the documentation there is no way to rename fields within arrays. Your only option is to iterate over your collection documents, read them and update each with $unset old/$set new operations.

Alex
  • 21,273
  • 10
  • 61
  • 73