这是我的请求正文
{"old":[{"coba": "A"}, {"cobak": "B"}], "new":[{"coba": "C"},{"cobak": "D"}]}
这是我的代码
function getOld(){
const data = request.body;
for(i = 0; i < data.old.lenght; i++) {
return data.old[i]
}
}
function getNew(){
const data = request.body;
for(i = 0; i < data.new.lenght; i++) {
return data.new[i]
}
}
const reqOld = getOld();
const reqNew = getNew();
db.cb.updateMany({$and: [reqOld]}, {$set: reqNew}, {upsert: false}, (error, data));
问题是将第一个请求正文更新为JSON数组,并且无法更新所有文档
答案 0 :(得分:0)
lenght
的拼写。_id
(async () => {
for (let i = 0; i < request.body.old.length; i++) {
const newItem = request.body.new[i];
const oldItem = request.body.old[i];
await db.cb.update(oldItem, {$set: newItem });
}
})()