【问题标题】:How to add json object as a type for attributes in sails-mongo如何在sails-mongo中添加json对象作为属性类型
【发布时间】:2015-01-26 23:26:48
【问题描述】:

Document.js

module.exports = {

  attributes: {

    type: {
        type: 'string'
    },
    createdBy: {
        model: 'User',
        required: true
    },
    body: {
        type: 'string'
    },
    comments: {
        model: 'Comments'
    },
    metaInfo: {
        type: 'json'
    }

 }

};

我想知道是否有任何方法可以编写类似于上面给出的模型,这样我就可以向 metaInfo 添加一个 json 对象,其中包含一个名称-值对.

例如: json: {名称:'项目',值:'MyFirstProject'}

这可以通过水线实现吗?

提前致谢。

【问题讨论】:

  • 是的,你可以!和你上面写的完全一样。这种类型允许您存储 JSON 对象以及数组
  • 感谢您的帮助!

标签: json mongodb sails.js models waterline


【解决方案1】:

我相信评论回答了您的问题。如果您需要任何进一步的帮助,您可以参考 Sails Github 页面中提出的这个问题的答案:JSON Array of Strings

【讨论】:

    猜你喜欢
    • 2021-10-03
    • 2019-06-15
    • 1970-01-01
    • 2017-09-20
    • 1970-01-01
    • 2018-09-13
    • 2015-09-21
    • 2016-12-30
    • 1970-01-01
    相关资源
    最近更新 更多