Hello @Alikhan_Oitan, Welcome to MongoDB Developer Forum
,
You can use update with aggregation pipeline starting from MongoDB 4.2,
- check query update only where
groupIdis exists -
$mapto iterate loop oflessonsand result your required fields
db.collection.update(
{ "lessons.groupId": { $exists: true } },
[{
$set: {
lessons: {
$map: {
input: "$lessons",
in: {
classid: "$$this.groupId",
someField: "$$this.someField"
}
}
}
}
}],
{ multi: true }
)