I have a server in nodejs with this schema in json:
var UserSchema = new Schema({
nick: String,
deviceId: String,
visivel: Boolean,
checks: [{date: {type:String},log: {type:Number},lng: {type:Number}}]
});
In the Post code I have something , like this:
.post(function(req, res){
var user = new User();
user.deviceId = req.body.deviceId;
console.log("ID: " + req.body.deviceId);
User.findOne({'deviceId': user.deviceId},'deviceId nick visivel checks',function(err, useritem){
user.nick = req.body.nick;
user.visivel = req.body.visivel;
if(req.body.checks != undefined){
req.body.checks.forEach(function(items){
console.log(items);
user.checks.push(items);
});
}
user.save(function(err){
if (err)
res.send(err);
res.json({ message: 'user save!' });
console.log('user save 1!');
})
}
}
when i make a post with a only one object in check array, the server have a exception:
Object # has no method 'forEach' at Promise. (/RalyAPP/server.js:268:22) at Promise. (/RalyAPP/node_modules/mongoose/node_modules/mpromise
/lib/promise.js:162:8) at Promise.emit (events.js:95:17) at Promise.emit (/RalyAPP/node_modules/mongoose/node_modules/mpromise/lib/pr
omise.js:79:38) at Promise.fulfill (/RalyAPP/node_modules/mongoose/node_modules/mpromise/lib
/promise.js:92:20) at /RalyAPP/node_modules/mongoose/lib/query.js:1833:13 at model.Document.init (/RalyAPP/node_modules/mongoose/lib/document.js:251:1
1) at completeOne (/RalyAPP/node_modules/mongoose/lib/query.js:1831:10) at /RalyAPP/node_modules/mongoose/lib/query.js:1799:11 at /RalyAPP/node_modules/mongoose/lib/utils.js:414:16
But if i make a post with more that one, run well and not have a exception.
Can help resolve this problem?
bests.