Mongoose - Version Error: No matching document found for id

前端 未结 4 1843
眼角桃花
眼角桃花 2020-12-12 01:59

Context: I have a Post Mongoose model that contains a csv_files array field to store csv strings. I make a fetch API

4条回答
  •  伪装坚强ぢ
    2020-12-12 02:35

    When saving an object to Mongo DB you have to understand that Mongo DB has a version control system in place. This helps ensure that if you save an object once, when saving it again you don't end up overwriting the previously saved data.

    This is the error you're seeing. If you want to force the object to update regardless of version control in this particular instance you may want to use .update() instead. This will force the object to be updated regardless of its currently saved state.

    This is because .save() watches and cares about version controls, while .update() will update the object regardless of version control.

提交回复
热议问题