'Updating (PUT) Postman with node.js JSON

i'am fighting with my code and POSTMAN for update a document JSON but i have a problem.


this is my document :

{
"_id": "624c3b7cxcc69d771f0sd872a6",
"idUsers": "101",
"nameSerie": "Name",
"essaiParcelle": "12",
"labelEssai": "000123091",
"microParcelle": [
    {
        "idMicro": "2768",
        "numMicroParcelle": "201"
    },
    {
        "idMicro": "2782",
        "numMicroParcelle": ""
    }
],
"dateObs": "07/04/2022",
"nbRepetition": "1",
"variablesUnique": [
    {
        "id": "1",
        "title": "title1",
        "idGrp": "0",
        "_id": "624c3b7cbc69d771f0s172a7"
    }
],
"VariableRep": [
    "201-1",
    "201-2",
],
"__v": 2
}

and this is my code in the back end :

router.put("/:_id", (req, res) => {
    const id_obs = req.params._id;
    Observation.findById(id_obs)
      .then((observation) => {
        observation.idUsers = req.body.idUsers;
        observation.nameSerie = req.body.nameSerie;
        observation.essaiParcelle = req.body.essaiParcelle;
        observation.microParcelle = req.body.microParcelle;
        observation.dateObs = req.body.dateObs;
        observation.nbRepetition = req.body.nbRepetition;
        observation.variableUnique = req.body.variableUnique;
        observation.variableRep = req.body.variableRep;
        
        return observation.save();
      })
      .then(result => { 
          res.send(result)
      })
      .catch((err) => console.log(err));
  });

and for the last this is the Schema :

   const UserSchema = new mongoose.Schema({

    idUsers : {type : String }, 
    nameSerie : {type : String }, 
    essaiParcelle : {type : String }, 
    labelEssai : {type : String },
    microParcelle : [],
    dateObs : {type : String}, 
    nbRepetition : {type : String  },
    variablesUnique :[{
        id : {type: String},
        title : { type : String},
        idGrp : {type : String}
    }],
    VariableRep : [],
})

the Problem is i can update with postman :

  • idUsers
  • nameSerie
  • essaiParcelle
  • labelEssai
  • dateObs
  • nbRepetition

But i can't update the others what is in Array and Object :

  • microParcelle
  • variablesUnique
  • VariableRep


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source