I need to update the document's array element in mongodb, I have multiple ids of that array. I need to update the matching element in that array.
data= [
{
"planId" : "plan_FVNvrmjWT7fRDY",
"startTime": ISODate("2019-07-30T07:05:23.000Z")
},
{
"planId" : "plan_FVNvCvm7Qg5uYB",
"startTime": ISODate("2019-07-30T07:05:23.000Z"),
},
{
"planId" : "plan_FVNvrmjWT7fRAS",
"startTime": ISODate("2019-07-30T07:05:41.000Z"),
}
]
document = {
"_id" : ObjectId("5d3fec3982d76f26f34afdc5"),
"customerId" : ObjectId("5d383013647a3c42835fd7e6"),
"__v" : 0,
"createdAt" : ISODate("2019-07-30T07:05:29.986Z"),
"subscriptions" : [
{
"_id" : ObjectId("5d3fec39c81f463a257862d0"),
"planId" : "plan_FVNvrmjWT7fRDY",
"startDate" : ISODate("2019-07-30T07:05:23.000Z"),
"endDate" : ISODate("2019-08-30T07:05:23.000Z"),
"status" : "Active"
},
{
"_id" : ObjectId("5d3fec39c81f463a257862cf"),
"planId" : "plan_FVNvCvm7Qg5uYB",
"startDate" : ISODate("2019-07-30T07:05:23.000Z"),
"endDate" : ISODate("2019-08-30T07:05:23.000Z"),
"status" : "Active"
},
{
"_id" : ObjectId("5d3fec4bc81f463a257862d2"),
"planId" : "plan_FVNvrmjWT7fRAS",
"startDate" : ISODate("2019-07-30T07:05:41.000Z"),
"endDate" : ISODate("2019-08-30T07:05:41.000Z"),
"status" : "Active"
}
]
}
Start date should be updated for the matching plan id in a single database query.