猫鼬节省空数组

问题描述:

我有一个数组,我试图与猫鼬,但在回报我得到一个空数组我在做什么错插入,猫鼬节省空数组

我的架构:

let postSchema = mongoose.Schema({ 


    date   : { type: Date, default: Date.now }, 
    name   : String, 
    desc   : String, 
    type   : [] 


},{collection: 'Post'}); 

我插入:

console.log(req.body.type); //here i have something like ["Teste1","Teste2"] 
let post = new Post({ 
         name: req.body.descricao, 
         desc: req.body.desc 
         type: req.body.type 
        }); 

post.save((err, model) => { 

    if (err) console.log(err); 

    if (model) console.log(model); //ALL INSERTED but array is just type:[] 

}) 
+1

保存帖子时没有模型参数。 –

最好的方法是指定数组元素的类型。 例如,

type: [String] 

指定一个空数组相当于混合类型。 另请检查req.body.type的类型

console.log(typeof req.body.type)