使用node.js
和mongodb
1)。 MongoDb Schema
var userScore = new Schema({
child: {
quiz_level: {
current_level: {type:Number},
level_attempted: {
type: Array,
level_id: {type:Number},
level_complete: {type:Boolean},
level_score: {type:Number}
}
}
}
});
2)。节点js
try{
// var quiz = levelScoreQuiz.child;
var userObj = {
"child.quiz_level.level_attempted.level_score": req.body.score
};
var user = new levelScoreQuiz(userObj);
user.save(function(err, result){
if (err) {
console.log('Error While Saving the reuslt ' +err)
} else {
console.log("User score saved successfully");
res.json(result);
}
});
} catch(err){
console.log('Error While Saving the reuslt ' +err);
return next(err);
}
3)。 Json的结果 这将显示数组插入的空结果
{
"__v": 0,
"_id": "57832f610118546713d23466",
"child": {
"quiz_level": {
"level_attempted": [] //This is the empty array
}
}
}