so I want to rename groupId field name to classid in every document and every lessons element. Firstly I wrote some JS script operation, but then I learned that eval is deprecated and as a result forEach and script operations cannot be used. What is the aggregation I could use in this situation, the complete aggregation is also very welcome, of course.
I also came up with this kind of solution just now, but I could not use it in java, since scriptOps has been deprecated.
I am using import org.springframework.data.mongodb.core. I am not expecting you to answer this, but in the official documents and google there are no examples on mapping using org.springframework.data.mongodb.core.aggregation.VariableOperators.Map. I am not sure why, maybe this is a new update. Could you please give some example in Java and specifically org.springframework.data.mongodb.core.aggregation.VariableOperators.Map.
I came up with something like this using autocomplete hints, but that’s all. I don’t know how to finish from here.
final Query deletedQuery = Query.query(Criteria.where("deleted").is(true));
Update groupToClassUpdate = new Update().set("lessons", Map.itemsOf("$lessons").as("lesson").andApply());
template.updateMulti(deletedQuery, groupToClassUpdate, Timetable.class);
But using "lessons.groupId": { $exists: true} is sure helpful. I would add that too.