我正在使用node,angular和mongodb。我试图添加一个对象数组(来自角客户端)到数据库使用节点。问题是服务器不断产生[对象对象]'而不是实际的数组。
代码:
// 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);
});
});
输出:
[ { vid: 'vid', start: 'start', end: 'end', type: 'type' } ]
{ name: 'name',
videos: [ '[object Object]' ] } // this is the problem
我需要做些什么来解决这个问题?
答案 0 :(得分:0)
你应该看看util.inspect()
。它是专门为此设计的。
示例:
var util = require('util');
// your codez...
console.log(util.inspect(test));