There is a scheme:

var userSchema = new Schema({ field: {}, field2: {}, field3: { innerField1: String, innerField2: String, innerField3: String, innerField4: String, innerField5: String, innerField6: String } }); 

Imagine that the scheme is completely filled and I need to update some data.

Request example: (I do not know which fields in field3 will come to me, they can be completely different all the time)

 { field3: { innerField2: String, innerField4: String } } 

How can I update sample fields in "Field3" and not delete the rest?

  Schema.findOneAndUpdate({_id: userId}, {$set: req.body.field3}, function(err, res) {}); 

Does not work, removes the remaining fields: (

Waiting for your answers, thanks!

    1 answer 1

     Schema.UpdateById(userId, {$set:{"field3": req.body.field3}}, function(err, res) {});