V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
plantain
V2EX  ›  问与答

mongoose 怎么设置某个 collection 是 mixed?

  •  
  •   plantain · Oct 4, 2015 · 1552 views
    This topic created in 3871 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   ·   6174 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 02:38 · PVG 10:38 · LAX 19:38 · JFK 22:38
    ♥ Do have faith in what you're doing.