V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
plantain
V2EX  ›  问与答

mongoose 怎么设置某个 collection 是 mixed?

  •  
  •   plantain · 2015-10-04 11:34:35 +08:00 · 1148 次点击
    这是一个创建于 3142 天前的主题,其中的信息可能已经有所发展或是发生改变。

    文档里的例子是可以设置字段为 mixed ,比如这样:

    var schema = new Schema({
    ofMixed: [Schema.Types.Mixed]
    })

    我试了这样,似乎不行,只会保存_id 和_v :

    var schema = new Schema({
    [Schema.Types.Mixed]
    })
    var schema = new Schema({
    any:[Schema.Types.Mixed]
    })

    breeswish
        1
    breeswish  
       2015-10-04 11:38:42 +08:00   ❤️ 1
    [Schema.Types.Mixed] 代表元素类型任意的数组
    如果不需要数组,直接 Schema.Types.Mixed
    plantain
        2
    plantain  
    OP
       2015-10-04 11:43:59 +08:00
    @breeswish 上面写错了,我实际用的就是 Schema.Types.Mixed ,确实没效果,不过我刚才通过改结构解决了,改成
    {time:Date,content:Schema.Types.Mixed},日志总是有时间的,也可以达到目的了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1019 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 20:08 · PVG 04:08 · LAX 13:08 · JFK 16:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.