Puoi trasformare i valori data in formato stringa dentro un array usando $map insieme a $toDate.
db.students.aggregate([ { $addFields: { absences: { $map: { input: "$absences", as: "absence", in: { date: {$toDate: {$substr: ["$$absence.date", 0, {$subtract: [{$strLenCP: "$$absence.date"}, 5]}]}}, code: "$$absence.code", type: "$$absence.type", isPartial: "$$absence.isPartial" } } } } }, {$out: "students"} ])La fase $out riscrive i documenti trasformati nella collection. Su dataset molto grandi valuta $merge, che offre un controllo più granulare sull'operazione di scrittura.