pjlamb12
pjlamb12

Reputation: 2422

Sails.js Waterline Update Method

I'm using Waterline in my Sails.js App to query my mongo database. I'm able to get a record out based on multiple query paramaters, such as this:

Model.findOne({param1: params[0], param2: params[1]})...

That works great. I looked at the docs for .update() and copied that but it isn't working. I still need to update a record based on two parameters, so this is my update function:

Model.update(
    [{param1: params[0]}, {param2: params[1]}],
    [{field1: update[0]}, {field2: update[1]}]
).exec(function(err, updatedModel) {
    console.log(err);
    console.log(updatedModel);
});

From what I read, it looks like the first argument to the update method is an object or array of objects with the values you're querying on to update a record; then the second parameter is the updated fields.

I'm not getting an error or an updatedModel, however, which probably means that I'm not finding an object from the Model table in mongo that fits the requirements. But I know that the object is there and the parameters are correct. Any suggestions?

Also, here's a gist with the update function as well.

Upvotes: 0

Views: 1955

Answers (1)

Bonanza
Bonanza

Reputation: 1621

Params in update function are objects not arrays.

Model.update(
    {param1: params[0], param2: params[1]}, //this is find
    {field1: update[0], field2: update[1]} // this is update
).exec(function(err, updatedModel) {
    if(err)
        console.error(err);
    console.log(updatedModel);
});

Upvotes: 1

Related Questions