简体   繁体   中英

Embedded MongoDb Insertion using node js

I am inserting data using node js into mongodb, but it have encountered with an error

Syntax Error Unexpected token.

it will accepting value from front end and save data in backend. The req.params.score accepting the value from front end.

Please can any one can help?

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). Node js

try{

        var userObj = {

        child.quiz_level.level_attempted.level_score:req.params.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);
        }
var userObj = {

    "child.quiz_level.level_attempted.level_score": req.params.score

};

Try that, I had a similar problem earlier in the week and passing the object property as a string seemed to work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM