How does mongoose update the array?

  node.js, question

Must $pull be followed by $addtoSet?

Fidding has finally found a solution through various Baidu Google. Here, for the sake of others who are as confused as me, we should give generously!
All right, let’s not talk too much.
First of all, my data structure

var userSchema = new Schema({
 name : String,
 avatar: String,
 mobile_phone : Number,
 email : String,
 wx_id : String,
 password : String,
 nickname: String,
 birth_day: Number,
 birth_month : Number,
 birth_year : Number,
 message: [{
 sender: {type: ObjectId, ref:'users'},
 title: String,
 content: String,
 sort: Number,
 read: {type: Number, default: 0}, date: Date

Here I want to set the read value in message to 1 (default is 0)

//find user by id
 User.findById(id, function(err, user){
 //traverse user.message and find the message you want to modify according to msg_id.
 for(var i = 0;   i < user.message.length;  I plus)
 //If found
 if(user.message[i]._id == msg_id){
 //modify read to 1
 user.message[i].read = 1;
 //Mixed type because there is no specific constraint,
 //Therefore, it can be modified at will. Once the prototype is modified,
 //markModified () must be called
 //Pass in read to indicate that the attribute type has changed
 Json ({status: 1, error:' modification succeeded!'  });

In this way, mongoose in nodejs updates Array data. Generally speaking, it gets all the data, then modifies the data it wants to modify, and finally calls save method instead of pull and then set.
As for deleting $pull and adding $addToSet is a piece of cake, I will not say much.
All right. joining