Mongoose instance .save() not working

前端 未结 7 707
情歌与酒
情歌与酒 2020-12-30 00:43

I have a problem with Mongoose and MongoDb

It is very interesting that only Model.update works and save never works and does not even fire

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-30 01:42

    I have the same problem. my problem was about changing an array inside db, then when I try to use .save(), it didn't understand that I changed any thing, then the .save() didn't work. I just use markModified() before use .save() and my problem become solved.

    this is my code with problem: (not working)

    club.members[index].name = new_name;
    club.save();
    

    this is my solved code: (working)

    club.members[index].name = new_name;
    club.markModified('members');
    club.save();
    

    enjoy!

提交回复
热议问题