Arrays 将数组添加到MongoDB/Mongoose集合时出错

Arrays 将数组添加到MongoDB/Mongoose集合时出错,arrays,node.js,mongodb,knockout.js,mongoose,Arrays,Node.js,Mongodb,Knockout.js,Mongoose,我试图将数组添加到Mongo文档中,但在路径“vendors” 这是我的模型: module.exports = { attributes: { vendors: { type: [String] }, description: { type: String } } }; 以下是我要创建的代码: var vendors = ko.observableArray(['foo','bar']); var desc = ko.obser

我试图将数组添加到Mongo文档中,但在路径“vendors”

这是我的模型:

module.exports = {
  attributes: {
    vendors: {
      type: [String]
    },
    description: {
      type: String
    }
  }
};
以下是我要创建的代码:

var vendors = ko.observableArray(['foo','bar']);
var desc = ko.observable('yadda yadda yadda');
var dto = {
    data: {
      vendors: vendors(),
      description: description()
    }
};
DataService.quoteRequest.create(dto);
音乐海岸

我对knockout.js不太熟悉,但对于Mongoose来说,它看起来不像是在定义和。您需要执行以下操作:

定义模式

var mongoose = require('mongoose'),
    Schema = mongoose.Schema;

var attributesSchema = new Schema({
  vendors: [String],
  description: String
});
创建模型

var Attributes = mongoose.model('Attribute',attributesSchema);
创建并保存文档

//create an attribute document
var attribute = new Attributes(
   { 
     vendors: vendorsArray,
     description: desc
    }
 );

attribute.save(function(err){
if(!err) console.log('Success');
}

您的自定义供应商代码是什么样子的?这是一个输入错误,应该是供应商。我修正了它。不管是否被淘汰,如果我在DTO中传递一个普通数组,我会得到相同的错误。你在哪里定义你的模式?