How to allow free-form JSON data within Mongoose documents?

前端 未结 2 840
一向
一向 2020-12-06 15:27

I\'m using Mongoose ODM to partially validate models before they are stored to MongoDB.

Is it possible to relax Mongoose schemata so that a given part of the documen

2条回答
  •  生来不讨喜
    2020-12-06 15:51

    When you modify the contents of a Mixed field like freeform_data, you need to notify Mongoose that you've changed its value by calling markModified(path) on the modified document or a subsequent save() call won't save it.

    For example:

    user.freeform_data = { foo: 'bar' };
    user.markModified('freeform_data');
    user.save();
    

提交回复
热议问题