Thursday, 16 March 2017

How to make mongoose new data (like comment)

Always Thank you for your answer and reading this script.

I have some problem

I want make comment system and use moongoose.

I tried like this. <↓ Part of Router>

    app.get('/api/update',function(req,res){
    Book.update({battletag: 'moon'},
    {$set:{ "herodata" :{'comeent':"heelo!!"}}},
    {upsert:true,multi:true},function(err,output){


        if(err) return res.status(500).json({error: 'database failure'});
        console.log(output);
        if(!output.n) return res.status(404).json({error: 'book not found'});
        res.json({message : 'book update!'});
    })
})

<↓ Part of Schema>

var Schema = mongoose.Schema;

var userSchema = new Schema({
    battletag: String,
    herodata: [{}],
    published_date: { type: Date, default: Date.now  } 

But not make comment.

If i don't make schema not add anything? <↓ this is data of result>

{
"_id": {
    "$oid": "58cab6744c41310e1480d3b1"
},
"battletag": "moon",
"published_date": {
    "$date": "2017-03-17T00:00:00.000Z"
},
"herodata": [
    {
        "comeent": "heelo!!"
         //not making comment...just work update
    }
],
"__v": 0

}

See that? not make comment just work update.

How do i do add new key : value?

Thank you and Regards. Have a good day!



via King in the world.

No comments:

Post a Comment