0

I have a collection named products in which I want to update the code which have the empty field under options.stores.code structure is as follow:-

{
"_id": ObjectId(),
"sku": "V4696-DR-V33",
"options": [
    {
        "sku": "8903689984338",
        "stores": [
            {
                "code": "AND1",
                "zipcode": "110070",
                "inventory": -5000
            },
            {
                "code": "AND2",
                "zipcode": "201010",
                "inventory": -5000
            },
            {
                "code": "AND3",
                "zipcode": "411001",
                "inventory": -5000
            },
            {
                "code": "AND4",
                "zipcode": " 700020",
                "inventory": -5000
            }
        ],
    },
    {
        "sku": "1742564789",
        "stores": [
            {
                "code": "AND1",
                "zipcode": "110070",
                "inventory": -5000
            },
            {
                "code": "AND2",
                "zipcode": "201010",
                "inventory": -5000
            },
            {
                "code": "AND3",
                "zipcode": "411001",
                "inventory": -5000
            },
            {
                "code": "AND8",
                "zipcode": " 700020",
                "inventory": -5000
            }
        ],
    },

]

}

Want to update the inventory, which have the same code.

Neo
  • 153
  • 1
  • 2
  • 9
  • you may find answer here [link](http://stackoverflow.com/questions/32733790/want-to-update-array-of-array-object-value-in-mongo) – Ashesh Khatri Sep 24 '15 at 10:21
  • Thanks for the reply. I have checked the query is working only for the single object inside the array.but not for the all the matched element. – Neo Sep 24 '15 at 10:24

2 Answers2

0

For updating empty store codes:

db.products.update({"code":""},{$set:{"code":"new value"}}
Abie
  • 624
  • 5
  • 12
0

using the python script use any loop for this update........... and made a slight modification------{$set:{"options.(loop variable).stores.$.inventory":}} this can help for query

Ashesh Khatri
  • 162
  • 2
  • 11