I have a collection. Each has a field studentUnitList which is Array of object. Inside this we have studentTopicList which is again Array of object. Structure of the document is:
{
"_id" : "",
"studentId" : "",
"subjectId" : "",
"completionPercentage" : 0.0,
"subjectName" : "",
"numberOfVideos" : NumberInt(312),
"catalogueId" : "",
"totalVideoLengthInSec" : NumberLong(209301),
"lastVisitedDate" : ISODate("2019-09-07T16:55:35.862+0000"),
"studentCatalogueId" : "",
"lastWatchedSubTopic" : {
"studentUnitId" : "",
"studentTopicId" : "",
"studentSubTopicId" : "",
"videoCompletionInSeconds" : NumberLong(12)
},
"studentUnitList" : [
{
"_id" : "",
"unitId" : "",
"unitName" : "",
"completionPercentage" : 0.0,
"totalVideoLengthInSec" : NumberLong(38024),
"studentTopicList" : [
{
"_id" : "",
"topicId" : "",
"topicName" : "",
"completionPercentage" : 0.0,
"totalVideoLengthInSec" : NumberLong(2151),
"studentContents" : [
{
"contentType" : "SUBTOPIC",
"subTopic" : {
"_id" : "",
"subTopicId" : "",
"subTopicName" : "",
"pageContentId" : "",
"videoLengthInSeconds" : NumberLong(2151),
"videoCompletionInSeconds" : NumberLong(0),
"videoCompletionPercentage" : 0.0
}
}
]
},
{
"_id" : "",
"topicId" : "",
"topicName" : "",
"completionPercentage" : 0.0,
"totalVideoLengthInSec" : NumberLong(1903),
"studentContents" : [
{
"contentType" : "SUBTOPIC",
"subTopic" : {
"_id" : "",
"subTopicId" : "",
"subTopicName" : "",
"pageContentId" : "",
"videoLengthInSeconds" : NumberLong(491),
"videoCompletionInSeconds" : NumberLong(0),
"videoCompletionPercentage" : 0.0
}
}
]
}
]
}
]
}
I want to add a boolean field "active" to each and every object of studentUnitList, studentTopicList, subTopic.
After adding field document will look like:
{
"_id" : "",
"studentId" : "",
"subjectId" : "",
"completionPercentage" : 0.0,
"subjectName" : "",
"numberOfVideos" : NumberInt(312),
"catalogueId" : "",
"totalVideoLengthInSec" : NumberLong(209301),
"lastVisitedDate" : ISODate("2019-09-07T16:55:35.862+0000"),
"studentCatalogueId" : "",
"lastWatchedSubTopic" : {
"studentUnitId" : "",
"studentTopicId" : "",
"studentSubTopicId" : "",
"videoCompletionInSeconds" : NumberLong(12)
},
"studentUnitList" : [
{
"_id" : "",
"unitId" : "",
"unitName" : "",
"completionPercentage" : 0.0,
"totalVideoLengthInSec" : NumberLong(38024),
"active": true,
"studentTopicList" : [
{
"_id" : "",
"topicId" : "",
"topicName" : "",
"completionPercentage" : 0.0,
"totalVideoLengthInSec" : NumberLong(2151),
"active": true,
"studentContents" : [
{
"contentType" : "SUBTOPIC",
"subTopic" : {
"_id" : "",
"subTopicId" : "",
"subTopicName" : "",
"pageContentId" : "",
"active": true,
"videoLengthInSeconds" : NumberLong(2151),
"videoCompletionInSeconds" : NumberLong(0),
"videoCompletionPercentage" : 0.0
}
}
]
},
{
"_id" : "",
"topicId" : "",
"topicName" : "",
"completionPercentage" : 0.0,
"totalVideoLengthInSec" : NumberLong(1903),
"active": true,
"studentContents" : [
{
"contentType" : "SUBTOPIC",
"subTopic" : {
"_id" : "",
"subTopicId" : "",
"subTopicName" : "",
"pageContentId" : "",
"active": true,
"videoLengthInSeconds" : NumberLong(491),
"videoCompletionInSeconds" : NumberLong(0),
"videoCompletionPercentage" : 0.0
}
}
]
}
]
}
]
}
I need a query or aggregation script to do the job.