-1

I have following document structure

{
   assets : {
              type : [
                       {
                        type : spread
                        scene : [
                                    {
                                      ....
                                    },
                                    {
                                      ....
                                    }

                                ] 
                       }
                     ]      
            }

}

So I want to add new element in "scene" array with match condition of type "spread" in same document

How can I write Mongo Update query for the same ?

1 Answer 1

0

Following is example array

{
   assets : {
              type : [
                       {
                        type : spread
                        scene : [
                                    {
                                      ....
                                    },
                                    {
                                      ....
                                    }

                                ] 
                       }
                     ]      
            }

}

Reference link MongoDB & Meteor - Query to push into nested array does not work, no error thrown

And query which insert new element in scene array is

db.PhotostoryDesigner.update(
    { 
        "photostoryId":"123", 
        "assets.type.type":"spreads" 
    },
    {"$push": { 
        'assets.type.$.scene':{"$each":[
            {
              "scene_id": "1",
              "name": "Ad hoc 1",
              "spread": [
                {
                  "spreadId": "7725",
                  "name": "PAGE 1-2",
                  "asset": []
                }
              ]
            }
        ]}}
    }
);
Sign up to request clarification or add additional context in comments.

Comments

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.