Re: updating nested array elements

From: Lavi Bharath <lavibharath@xxxxxxxxx>
To: mongodb-user <mongodb-user@xxxxxxxxxxxxxxxx>
Date: Thu, 12 May 2016 18:29:48 -0700 (PDT)
Why ads?
Hi WAn,
Thanks.
Sorry for the confusion. Its per_data_status.

The original nested array is below(full data structure in the original post.

 {
                    "id" : "9009",
                    "dir" : "Project_9009",
                    "Status" : "SUCCESS",
                    "StatsSubmission" : "TODO",
                    "ArchiveSubmission" : "TODO"
                }

In this I just want to change two status and hence it gets updated as below:

 {
                    "id" : "9009",
                    "dir" : "Project_9009",
                    "Status" : "SUCCESS",
                    "StatsSubmission" : "DONE",
                    "ArchiveSubmission" : "DONE"
                }

Thanks for your time.
On Wednesday, May 11, 2016 at 12:55:39 PM UTC+8, Lavi Bharath wrote:

I have a nested array as below. I am trying to update a nested array as 
below. But not able to complete the operation successfully
{
    "_id" : ObjectId("57304a006f42802df624aaa6"),
    "test" : "Milan",
    "timestamp" : NumberLong(1462781256018),
    "analysis" : [ 
        {
            "userName" : "xxx",
            "Status" : "SUCCESS",
            "startTime" : "2016-05-09T18-35-23.601813",
            "EndTimes" : "2016-05-09T18-40-02.891451",
            "analysis_id" : "2016-05-09T18-35-23.601813",
            "per_data_status" : [ 
                {
                    "id" : "3676",
                    "dir" : "Project_3676",
                    "Status" : "SUCCESS",
                    "StatsSubmission" : "TODO",
                    "ArchiveSubmission" : "TODO"
                },               
                {
                    "id" : "9009",
                    "dir" : "Project_9009",
                    "Status" : "SUCCESS",
                    "StatsSubmission" : "TODO",
                    "ArchiveSubmission" : "TODO"
                }
            ]
        }
    ]
}

db.getCollection('datacomplete').update(
    {test: "Milan", 'analysis.analysis_id' : "2016-05-09T18-35-23.601813", 
"analysis.per_data_status.id" : "9009"},
    {$set: 
        { 
            "per_mux_status.$": 
                    {
                    "id" : "9009",
                    "dir" : "9009",
                    "Status" : "SUCCESS",
                    "StatsSubmission" : "DONE",
                    "ArchiveSubmission" : "DONE"
                    }            
            }
        }      
)   

Thanks. PLease check my above query hence I am able to update


-- 
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.org/manual/support/
--- 
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@xxxxxxxxxxxxxxxx.
To post to this group, send email to mongodb-user@xxxxxxxxxxxxxxxx.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/e1737145-6c95-4a8c-b307-3fcb4fc11f86%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Why ads?