plantain
V2EX  ›  问与答

mongoose 怎么设置某个 collection 是 mixed?

  •  
  •   plantain · Oct 4, 2015 · 1560 views
    This topic created in 3875 days ago, the information mentioned may be changed or developed.

    文档里的例子是可以设置字段为 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  
       Oct 4, 2015   ❤️ 1
    [Schema.Types.Mixed] 代表元素类型任意的数组
    如果不需要数组,直接 Schema.Types.Mixed
    plantain
        2
    plantain  
    OP
       Oct 4, 2015
    @breeswish 上面写错了,我实际用的就是 Schema.Types.Mixed ,确实没效果,不过我刚才通过改结构解决了,改成
    {time:Date,content:Schema.Types.Mixed},日志总是有时间的,也可以达到目的了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5816 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 47ms · UTC 01:55 · PVG 09:55 · LAX 18:55 · JFK 21:55
    ♥ Do have faith in what you're doing.