I would like to be able to use hurl.it (or similar service) to test saving some data to my Mongoose DB. I can't figure out how to structure the parameters so that I can save nested arrays.
Here's my schema:
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}
});
I've tried sending costs.price and costs.0.price as request params, and also tried sending a JSON object as a string in the request body. It will save the document with all of the simple variables, title, subtitle, etc., but it just ignores the costs information.
EDIT:
Thought I should mention that passing in costs.0.price as a param crashes node. Here's the dump:
/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...