Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(main): adding info about remove undefined values for doc client … #5725

Merged
merged 3 commits into from
Feb 5, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 43 additions & 6 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,13 +458,17 @@ S3 client in v3 supports S3 global client, or following region redirects, if an

## DynamoDB Document Client

In v2, you can use the [`AWS.DynamoDB.DocumentClient` class](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html)
to call DynamoDB API with native JavaScript types like Buffer, Array, and Object. It thus simplifies working with items
in Amazon DynamoDB by abstracting away the notion of attribute values.
### Basic Usage of DynamoDB Document Client in v3

In v3, equivalent [`@aws-sdk/lib-dynamodb`](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_lib_dynamodb.html)
is available. It's similar to normal service clients from v3 SDK, with the difference that it takes a basic DynamoDB
client in its constructor. Here's an brief example:
- In v2, you can use the [`AWS.DynamoDB.DocumentClient` class](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html)
to call DynamoDB API with native JavaScript types like Buffer, Array, and Object. It thus simplifies working with items
RanVaknin marked this conversation as resolved.
Show resolved Hide resolved
in Amazon DynamoDB by abstracting away the notion of attribute values.

- In v3, equivalent [`@aws-sdk/lib-dynamodb`](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_lib_dynamodb.html)
RanVaknin marked this conversation as resolved.
Show resolved Hide resolved
is available. It's similar to normal service clients from v3 SDK, with the difference that it takes a basic DynamoDB
client in its constructor.

Example:

```javascript
import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; // ES6 import
Expand All @@ -489,6 +493,39 @@ await ddbDocClient.send(
);
```

### Undefined Values in Marshalling

- In v2 `undefined` values in objects were automatically omitted during the marshalling process to DynamoDB.

- In v3, using [`@aws-sdk/lib-dynamodb`](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_lib_dynamodb.html), the default behavior has changed: `undefined` values in objects are now included during marshalling. Developers need to explicitly manage undefined values to exclude them using the `removeUndefinedValues` flag.

Example:

```js
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocumentClient, PutCommand } from "@aws-sdk/lib-dynamodb";
import { marshall } from "@aws-sdk/util-dynamodb";

const client = new DynamoDBClient({});

const ddbDocClient = DynamoDBDocumentClient.from(client);
RanVaknin marked this conversation as resolved.
Show resolved Hide resolved

const item = {
id: "123",
content: undefined,
};

const marshalledItem = marshall(item, { removeUndefinedValues: true });
RanVaknin marked this conversation as resolved.
Show resolved Hide resolved

// procceed with making the API call as usual:
await ddbDocClient.send(
new PutCommand({
TableName: "YourTableName",
Item: marshalledItem,
})
);
```

More examples and configurations are available in the [package README](https://github.com/aws/aws-sdk-js-v3/blob/main/lib/lib-dynamodb/README.md).

## Waiters
Expand Down
Loading