Skip to content

Commit

Permalink
Adding documentation for condition Model.update setting
Browse files Browse the repository at this point in the history
  • Loading branch information
fishcharlie committed Apr 4, 2020
1 parent 8c6d1e8 commit 1e5cf80
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docs/api/Model.md
Expand Up @@ -259,6 +259,7 @@ You can also pass in a `settings` object parameter to define extra settings for
| Name | Description | Type | Default |
|------|-------------|------|---------|
| return | What the function should return. Can be `document`, or `request`. In the event this is set to `request` the request Dynamoose will make to DynamoDB will be returned, and no request to DynamoDB will be made. | String | `document` |
| condition | This is an optional instance of a Condition for the update. | [dynamoose.Condition](Condition.md) | `null`

There are two different methods for specifying what you'd like to edit in the document. The first is you can just pass in the attribute name as the key, and the new value as the value. This will set the given attribute to the new value.

Expand All @@ -278,6 +279,25 @@ User.update({"id": 1}, {"name": "Bob"}, (error, user) => {
});
```

```js
// The following code below will only update the item if the `active` property on the existing document is set to true

const condition = new dynamoose.Condition().where("active").eq(true);


await User.update({"id": 1}, {"name": "Bob"}, {"condition": condition});

// OR

User.update({"id": 1}, {"name": "Bob"}, {"condition": condition}, (error, user) => {
if (error) {
console.error(error);
} else {
console.log(user);
}
});
```

The other method you can use is by using specific update types. These update types are as follows.

- `$SET` - This method will set the attribute to the new value (as shown above)
Expand Down

0 comments on commit 1e5cf80

Please sign in to comment.