I'm trying to update different values at different levels in a document in the database.
我正在尝试更新数据库中文档中不同级别的不同值。
The code snippet I am using is the following:
我使用的代码片段如下:
async actualizarTiempos(registroEventos): Promise<any> {
console.log(registroEventos);
const response = await registroEventos.eventos.map(async (evento) => {
const query = {
ficha: evento.ficha.ficha,
};
const update = {
$inc: {
acumulado: evento.horas,
'competencias.$[comp].acumulado': evento.horas,
'competencias.$[comp].resultados.$[resu].acumulado': evento.horas,
},
};
const arrayFilters = [
{
'comp.codigo': evento.competencia.codigo,
'resu.orden': evento.resultado.orden,
},
];
const registro = await this.gestorTModel.findOneAndUpdate(query, update, {
arrayFilters,
});
return {
registro,
};
});
But when I try to run the code it gives me the following error:
但是,当我尝试运行代码时,它给出了以下错误:
/home/juliandavidrealesdelaossa/Development/dds-backend/node_modules/mongodb/src/cmap/connection.ts:413
callback(new MongoServerError(document));
^
MongoServerError: Error parsing array filter :: caused by :: Expected a single top-level field name, found 'comp' and 'resu'
at Connection.onMessage (/home/juliandavidrealesdelaossa/Development/dds-backend/node_modules/mongodb/src/cmap/connection.ts:413:18)
at MessageStream.<anonymous> (/home/juliandavidrealesdelaossa/Development/dds-backend/node_modules/mongodb/src/cmap/connection.ts:243:56)
at MessageStream.emit (node:events:514:28)
at processIncomingData (/home/juliandavidrealesdelaossa/Development/dds-backend/node_modules/mongodb/src/cmap/message_stream.ts:187:12)
at MessageStream._write (/home/juliandavidrealesdelaossa/Development/dds-backend/node_modules/mongodb/src/cmap/message_stream.ts:68:5)
at writeOrBuffer (node:internal/streams/writable:392:12)
at _write (node:internal/streams/writable:333:10)
at MessageStream.Writable.write (node:internal/streams/writable:337:10)
at TLSSocket.ondata (node:internal/streams/readable:766:22)
at TLSSocket.emit (node:events:514:28)
更多回答
优秀答案推荐
我是一名优秀的程序员,十分优秀!