我希望能够使用hurl.it(或类似服务)来测试将一些数据保存到我的Mongoose数据库中。我无法弄清楚如何构造参数,以便我可以保存嵌套数组。
这是我的架构:
var Events = new Schema({
title: String,
subtitle: String,
start: Date,
end: Date,
description: String,
handle: String,
published: Boolean,
location: {
lat: String,
lng: String
},
costs: [{
price: Number,
description: String,
cost_type: {
type: String,
enum: ['Pre-Sale', 'Door', 'Online', 'Box Office', 'Suggested Donation', 'Discount', 'Children', 'Senior']
},
created: {type: Date}
}],
created: {type: Date}
});
我尝试将costs.price
和costs.0.price
作为请求参数发送,并尝试在请求正文中将JSON对象作为字符串发送。它将使用所有简单变量,标题,副标题等保存文档,但它只是忽略了成本信息。
修改
我想应该提一下,传递costs.0.price
作为参数崩溃节点。这是转储:
/node_modules/mongoose/lib/schema/documentarray.js:94
doc.validate(function (err) {
^
TypeError: Object #<Object> has no method 'validate'
at
/node_modules/mongoose/lib/schema/documentarray.js:94:13
at
/node_modules/mongoose/lib/schema/documentarray.js:102:9
at DocumentArray.SchemaType.doValidate (/node_modules/mongoose/lib/schematype.js:603:22)
at DocumentArray.doValidate (/node_modules/mongoose/lib/schema/documentarray.js:73:35)
at /node_modules/mongoose/lib/document.js:970:9
at process._tickCallback (node.js:415:13)
24 Mar 10:11:07 - [nodemon] app crashed - waiting for file changes before starting...