【发布时间】:2019-09-10 23:15:24
【问题描述】:
我的问题是更新文档的特定字段。 假设我们有多个输入字段,当我只是更改文档的一个字段时,其余字段将为空,因为我只是更新其中一个。有什么简单的方法可以更新一个字段而其余字段不变。
我可以给出一个 switch case 或 if-else 但我不认为这是一个 解决此类问题的适当方法。
updateChr:async ( args: any) => {
try {
const data = await Client.findByIdAndUpdate(args.clientId,
{$set:
{
chronology:{
status: args.clientInput.status,
note:args.clientInput.note,
date: args.clientInput.date,
file:{
filename:args.clientInput.file.filename,
data:args.clientInput.file.data,
type:args.clientInput.file.type,
size:args.clientInput.file.size,
}
}
},
}
,{useFindAndModify: false})
return transformClient(data);
} catch (err) {
throw err;
}
},
【问题讨论】:
标签: javascript node.js reactjs mongodb mongoose