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

前端 未结 2 833
一向
一向 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:49

    Mongeese : a mongoose multi-database helper/hack module https://github.com/donpark/mongeese

    Disclaimer: I was looking to connect to two MongoDB instances in the same app and gave up. So I haven't tried it.

    0 讨论(0)
  • 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();
    
    0 讨论(0)
提交回复
热议问题