Rahul Saxena
Rahul Saxena

Reputation: 465

getting issue in update query in sails js

I am new in sails js and getting some issue my update query show updated successfully but it does not update the record in mongodb collection. I don't where i am doing silly mistake.

Here is controller function

edit: function(req, res){
    var uid = req.params.id;
    console.log("Request body----------" +uid);

    console.log(req.body.heading);
    console.log(req.body.message);
    Dashboard.update(
    { _id : uid },
    {title : "req.body.heading" , description : "req.body.message" }).exec(function(err, doc){
    if(err){
        console.log("Error while update"+err);
    }else{
        console.log("Successfuly Updated");
        res.redirect('dashboard/index');
    }
    });     
}

This is model file:

module.exports = {

  attributes: {
    title:{
         type:'string',
         //required:true,
         columnName:'title'
    },
    description: {
         type:'text',
         columnName:'description'
    },
    posted_by: {
        type: 'integer',
        columnName: 'posted_by'
    }

  }

Console message shows this

Successfully Updated

Any one help will be appreciated Thank you in advance

Upvotes: 1

Views: 216

Answers (1)

Andi N. Dirgantara
Andi N. Dirgantara

Reputation: 2051

Use id istead of _id like

Dashboard.update(
  { id : uid },
  {title : "req.body.heading" , description : "req.body.message" }
)

It's Waterline conventions.

Upvotes: 2

Related Questions