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.

2
  • you may find answer here link Commented Sep 24, 2015 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. Commented Sep 24, 2015 at 10:24

2 Answers 2

0

For updating empty store codes:

db.products.update({"code":""},{$set:{"code":"new value"}}
Sign up to request clarification or add additional context in comments.

1 Comment

This is normal update, but it will not the way I am expecting.
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

3 Comments

can we do with mongo query without using any loop, as I have many records to update.
there is no direct way to update using mongo query, u have to use any loop.
k thanks will work on this solution and post you the update : ) Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.