How to modify only a few value? of object by mongoose

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?

Mar.22,2021

UserInfoModel.findOneAndUpdate(
{
    userId
},
{
    "wxInfon.nickName" : nickName,
    "wxInfon.avatarUrl" : avatarUrl,
    "wxInfon.gender" : gender,
    "wxInfon.city" : city,
    "wxInfon.province" : province,
    "wxInfon.country" : country,
    "wxInfon.language" : language
});

you just need to use the update method to update the items you want to update


try $set Bar
https://docs.mongodb.com/manu.

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b30ecf-2bd47.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b30ecf-2bd47.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?