the general situation is about the same as this https://cnodejs.org/topic/50d.
schema:
const userInfoSchema = new Schema({
uId: String,
userId: Number,
wxInfo: {
unionid: String,
openid: String,
nickName: String,
avatarUrl: String,
gender: Number,
city: String,
province: String,
country: String,
language: String,
},
createTimeUtc: { type: Date, default: Date.now },
updateTimeUtc: { type: Date, default: Date.now },
})
node:
is now used like this
await UserInfoModel.findOneAndUpdate({ userId }, {
$set: {
"wxInfo.nickName": nickName,
"wxInfo.avatarUrl": avatarUrl,
"wxInfo.gender": gender,
"wxInfo.city": city,
"wxInfo.province": province,
"wxInfo.country": country,
"wxInfo.language": language,
updateTimeUtc: Date.now(),
}
});
if you write like this, you will update all wxInfo:
UserInfoModel.findOneAndUpdate({ userId }, {
wxInfo: {
nickName, avatarUrl, gender, city, province, country, language,
},
});
what is the simple way to write so that nickName, avatarUrl, gender, city, province, country, language can be fully updated, while other unuploaded ones remain the same?