C # mongodb: cómo actualizar elementos de matriz anidados

Tengo la siguiente estructura JSON que representa un elemento

{
    Id: "a",
    Array1: [{
        Id: "b",
        Array2: [{
            Id: "c",
            Array3: [
                {...}
            ]
        }]
    }]
}

Necesito poder reemplazar el elemento de matriz enArray2 con un nuevo artículo o para reemplazar soloArray3 con una nueva matriz

Aquí está mi código para reemplazar el elemento de matriz enArray2:

await Collection.UpdateOneAsync(
    item => item.Id.Equals("a") &&
    item.Array1.Any(a => a.Id.Equals("b")) &&
    item.Array1[-1].Array2.Any(b => b.Id.Equals("c")),
    Builders<Item>.Update.Set(s => s.Array1[-1].Array2[-1], newArray2Item)
);

Al ejecutar este código, recibo este error:

"A write operation resulted in an error.
 Too many positional (i.e. '

Aquí está mi código para reemplazarArray3 dentroArray2:

await Collection.UpdateOneAsync(
        item => item.Id.Equals("a") &&
        item.Array1.Any(a => a.Id.Equals("b")) &&
        item.Array1[-1].Array2.Any(b => b.Id.Equals("c")),
        Builders<Item>.Update.Set(s => s.Array1[-1].Array2[-1].Array3, newArray3)
    );

Y este es el error:

"A write operation resulted in an error.
 Too many positional (i.e. '

Estoy usando el controlador C # MongoDB versión 2.5.0 y MongoDB versión 3.6.1

Encontré este boleto de JiraOperador posicional que empareja matrices anidadas que dice que el problema se solucionó y sugirieron esta sintaxis para la actualización

Update all matching documents in nested array:

db.coll.update({}, {$set: {“a.$[i].c.$[j].d”: 2}}, {arrayFilters: [{“i.b”: 0}, {“j.d”: 0}]})
Input: {a: [{b: 0, c: [{d: 0}, {d: 1}]}, {b: 1, c: [{d: 0}, {d: 1}]}]}
Output: {a: [{b: 0, c: [{d: 2}, {d: 1}]}, {b: 1, c: [{d: 0}, {d: 1}]}]}

Entonces lo convertí a mis elementos:

db.getCollection('Items').update(
{"Id": "a"},
{$set: {"Array1.$[i].Array2.$[j].Array3": [newArray3]}}, 
{arrayFilters: 
    [
        {"i.Id": "b"}, 
        {"j.Id": "c"}
    ]}
)

Y obtuve este error:

cannot use the part (Array1 of Array.$[i].Array2.$[j].Array3) to traverse the element

¿Alguna idea sobre cómo resolver este error?

) elements found in path 'Array1.$.Array2.

Aquí está mi código para reemplazarArray3 dentroArray2:

await Collection.UpdateOneAsync(
        item => item.Id.Equals("a") &&
        item.Array1.Any(a => a.Id.Equals("b")) &&
        item.Array1[-1].Array2.Any(b => b.Id.Equals("c")),
        Builders<Item>.Update.Set(s => s.Array1[-1].Array2[-1].Array3, newArray3)
    );

Y este es el error:

"A write operation resulted in an error.
 Too many positional (i.e. '$') elements found in path 'Array1.$.Array2.$.Array3'"

Estoy usando el controlador C # MongoDB versión 2.5.0 y MongoDB versión 3.6.1

Encontré este boleto de JiraOperador posicional que empareja matrices anidadas que dice que el problema se solucionó y sugirieron esta sintaxis para la actualización

Update all matching documents in nested array:

db.coll.update({}, {$set: {“a.$[i].c.$[j].d”: 2}}, {arrayFilters: [{“i.b”: 0}, {“j.d”: 0}]})
Input: {a: [{b: 0, c: [{d: 0}, {d: 1}]}, {b: 1, c: [{d: 0}, {d: 1}]}]}
Output: {a: [{b: 0, c: [{d: 2}, {d: 1}]}, {b: 1, c: [{d: 0}, {d: 1}]}]}

Entonces lo convertí a mis elementos:

db.getCollection('Items').update(
{"Id": "a"},
{$set: {"Array1.$[i].Array2.$[j].Array3": [newArray3]}}, 
{arrayFilters: 
    [
        {"i.Id": "b"}, 
        {"j.Id": "c"}
    ]}
)

Y obtuve este error:

cannot use the part (Array1 of Array.$[i].Array2.$[j].Array3) to traverse the element

¿Alguna idea sobre cómo resolver este error?

"

Aquí está mi código para reemplazarArray3 dentroArray2:

await Collection.UpdateOneAsync(
        item => item.Id.Equals("a") &&
        item.Array1.Any(a => a.Id.Equals("b")) &&
        item.Array1[-1].Array2.Any(b => b.Id.Equals("c")),
        Builders<Item>.Update.Set(s => s.Array1[-1].Array2[-1].Array3, newArray3)
    );

Y este es el error:

"A write operation resulted in an error.
 Too many positional (i.e. '$') elements found in path 'Array1.$.Array2.$.Array3'"

Estoy usando el controlador C # MongoDB versión 2.5.0 y MongoDB versión 3.6.1

Encontré este boleto de JiraOperador posicional que empareja matrices anidadas que dice que el problema se solucionó y sugirieron esta sintaxis para la actualización

Update all matching documents in nested array:

db.coll.update({}, {$set: {“a.$[i].c.$[j].d”: 2}}, {arrayFilters: [{“i.b”: 0}, {“j.d”: 0}]})
Input: {a: [{b: 0, c: [{d: 0}, {d: 1}]}, {b: 1, c: [{d: 0}, {d: 1}]}]}
Output: {a: [{b: 0, c: [{d: 2}, {d: 1}]}, {b: 1, c: [{d: 0}, {d: 1}]}]}

Entonces lo convertí a mis elementos:

db.getCollection('Items').update(
{"Id": "a"},
{$set: {"Array1.$[i].Array2.$[j].Array3": [newArray3]}}, 
{arrayFilters: 
    [
        {"i.Id": "b"}, 
        {"j.Id": "c"}
    ]}
)

Y obtuve este error:

cannot use the part (Array1 of Array.$[i].Array2.$[j].Array3) to traverse the element

¿Alguna idea sobre cómo resolver este error?

) elements found in path 'Array1.$.Array2.$.Array3'"

Estoy usando el controlador C # MongoDB versión 2.5.0 y MongoDB versión 3.6.1

Encontré este boleto de JiraOperador posicional que empareja matrices anidadas que dice que el problema se solucionó y sugirieron esta sintaxis para la actualización

Update all matching documents in nested array:

db.coll.update({}, {$set: {“a.$[i].c.$[j].d”: 2}}, {arrayFilters: [{“i.b”: 0}, {“j.d”: 0}]})
Input: {a: [{b: 0, c: [{d: 0}, {d: 1}]}, {b: 1, c: [{d: 0}, {d: 1}]}]}
Output: {a: [{b: 0, c: [{d: 2}, {d: 1}]}, {b: 1, c: [{d: 0}, {d: 1}]}]}

Entonces lo convertí a mis elementos:

db.getCollection('Items').update(
{"Id": "a"},
{$set: {"Array1.$[i].Array2.$[j].Array3": [newArray3]}}, 
{arrayFilters: 
    [
        {"i.Id": "b"}, 
        {"j.Id": "c"}
    ]}
)

Y obtuve este error:

cannot use the part (Array1 of Array.$[i].Array2.$[j].Array3) to traverse the element

¿Alguna idea sobre cómo resolver este error?

) elements found in path 'Array1.$.Array2.

Aquí está mi código para reemplazarArray3 dentroArray2:

await Collection.UpdateOneAsync(
        item => item.Id.Equals("a") &&
        item.Array1.Any(a => a.Id.Equals("b")) &&
        item.Array1[-1].Array2.Any(b => b.Id.Equals("c")),
        Builders<Item>.Update.Set(s => s.Array1[-1].Array2[-1].Array3, newArray3)
    );

Y este es el error:

"A write operation resulted in an error.
 Too many positional (i.e. '$') elements found in path 'Array1.$.Array2.$.Array3'"

Estoy usando el controlador C # MongoDB versión 2.5.0 y MongoDB versión 3.6.1

Encontré este boleto de JiraOperador posicional que empareja matrices anidadas que dice que el problema se solucionó y sugirieron esta sintaxis para la actualización

Update all matching documents in nested array:

db.coll.update({}, {$set: {“a.$[i].c.$[j].d”: 2}}, {arrayFilters: [{“i.b”: 0}, {“j.d”: 0}]})
Input: {a: [{b: 0, c: [{d: 0}, {d: 1}]}, {b: 1, c: [{d: 0}, {d: 1}]}]}
Output: {a: [{b: 0, c: [{d: 2}, {d: 1}]}, {b: 1, c: [{d: 0}, {d: 1}]}]}

Entonces lo convertí a mis elementos:

db.getCollection('Items').update(
{"Id": "a"},
{$set: {"Array1.$[i].Array2.$[j].Array3": [newArray3]}}, 
{arrayFilters: 
    [
        {"i.Id": "b"}, 
        {"j.Id": "c"}
    ]}
)

Y obtuve este error:

cannot use the part (Array1 of Array.$[i].Array2.$[j].Array3) to traverse the element

¿Alguna idea sobre cómo resolver este error?

"

Aquí está mi código para reemplazarArray3 dentroArray2:

await Collection.UpdateOneAsync(
        item => item.Id.Equals("a") &&
        item.Array1.Any(a => a.Id.Equals("b")) &&
        item.Array1[-1].Array2.Any(b => b.Id.Equals("c")),
        Builders<Item>.Update.Set(s => s.Array1[-1].Array2[-1].Array3, newArray3)
    );

Y este es el error:

"A write operation resulted in an error.
 Too many positional (i.e. '$') elements found in path 'Array1.$.Array2.$.Array3'"

Estoy usando el controlador C # MongoDB versión 2.5.0 y MongoDB versión 3.6.1

Encontré este boleto de JiraOperador posicional que empareja matrices anidadas que dice que el problema se solucionó y sugirieron esta sintaxis para la actualización

Update all matching documents in nested array:

db.coll.update({}, {$set: {“a.$[i].c.$[j].d”: 2}}, {arrayFilters: [{“i.b”: 0}, {“j.d”: 0}]})
Input: {a: [{b: 0, c: [{d: 0}, {d: 1}]}, {b: 1, c: [{d: 0}, {d: 1}]}]}
Output: {a: [{b: 0, c: [{d: 2}, {d: 1}]}, {b: 1, c: [{d: 0}, {d: 1}]}]}

Entonces lo convertí a mis elementos:

db.getCollection('Items').update(
{"Id": "a"},
{$set: {"Array1.$[i].Array2.$[j].Array3": [newArray3]}}, 
{arrayFilters: 
    [
        {"i.Id": "b"}, 
        {"j.Id": "c"}
    ]}
)

Y obtuve este error:

cannot use the part (Array1 of Array.$[i].Array2.$[j].Array3) to traverse the element

¿Alguna idea sobre cómo resolver este error?

Respuestas a la pregunta(1)

Su respuesta a la pregunta