Mongoose save() not updating value in an array in database document

后端 未结 3 710
没有蜡笔的小新
没有蜡笔的小新 2021-01-31 15:59

I am trying to update a document in a collection (units) using GUI and after it gets updated I want to update the value (user.Units which is an array of Unit names) in collecti

相关标签:
3条回答
  • 2021-01-31 16:13

    Maybe notify mongooose the dataset has changed like this :

    doc.markModified('pathToYourAttribute') 
    

    From the docs http://mongoosejs.com/docs/schematypes.html

    person.anything = { x: [3, 4, { y: "changed" }] }; 
    person.markModified('anything');
    

    Hope it helps!

    0 讨论(0)
  • 2021-01-31 16:23

    i replaced the save methud with this statment: Client_data.Unit.updateOne({_id: unit._id},unit);

    0 讨论(0)
  • 2021-01-31 16:26

    Refer to this issue. One way to solve this would be not to update your array via the classic array Index method. So do this

    doc.array.set(index, value);
    

    Instead of

    doc.array[index] = value;
    

    also view the FAQ and doc for more details.

    0 讨论(0)
提交回复
热议问题