Es porque está utilizando el operador $:el operador posicional $ identifica un elemento (no múltiple) en una matriz para actualizar sin especificar explícitamente la posición del elemento en la matriz. Para proyectar o devolver un elemento de matriz de una operación de lectura, consulte el operador de proyección $.
Puede usar el siguiente código para hacerlo:
db.playground.find({
$and: [
{
"TargetSegments.Colors": {
$exists: true
}
},
{
"ProjectFileId": 1
},
{
"SourceLanguageId": 2
},
{
"TargetSegments": {
$elemMatch: {
"LanguageId": 1
}
}
}
]
}).forEach(function(item)
{
var targets = item.TargetSegments;
for(var index = 0; index < targets.length; index++)
{
var target = targets[index];
target.Segment = null,
target.Colors= [],
target.Widths= [],
target.Heights= []
}
db.playground.save(item);
});