I am using node, angular and mongodb. I am trying to add an array of objects (coming from angular client) to the db using node. The problem is that the server keeps producing '[object Object]' instead of the actual array.
Code:
// Schema
var testSchema = new mongoose.Schema({
name: String,
videos: [ {
vid: String, // id of the video
start: String, // desired start time
end: String, // desired end time
type: String
}]
});
// Model
var Test = mongoose.model('Test', testSchema);
// Add new test
app.post('/api/tests', function (req, res, next)
{
// videos from client, output suggests that this is fine
console.log( req.body.testVideos );
// now creating it and testVideos not fine anymore
var test = new Test({
name: req.body.testName,
videos: req.body.testVideos
});
// see output
console.log( test );
test.save(function(err)
{
if (err) return next(err);
res.send(200);
});
});
Output:
[ { vid: 'vid', start: 'start', end: 'end', type: 'type' } ]
{ name: 'name',
videos: [ '[object Object]' ] } // this is the problem
What do I need to do to get around this problem?