Skip to content

Commit 4d6db90

Browse files
authored
docs(main): adding info about remove undefined values for doc client … (#5725)
* docs(main): adding info about remove undefined values for doc client marshalling * docs(main): fixing code example to not use marshall function * docs(main): fixing description for basic use section --------- Co-authored-by: RanVaknin <[email protected]>
1 parent 28bfbf8 commit 4d6db90

File tree

1 file changed

+42
-6
lines changed

1 file changed

+42
-6
lines changed

UPGRADING.md

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -458,13 +458,17 @@ S3 client in v3 supports S3 global client, or following region redirects, if an
458458

459459
## DynamoDB Document Client
460460

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

465-
In v3, equivalent [`@aws-sdk/lib-dynamodb`](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_lib_dynamodb.html)
466-
is available. It's similar to normal service clients from v3 SDK, with the difference that it takes a basic DynamoDB
467-
client in its constructor. Here's an brief example:
463+
- In v2, you can use the [`AWS.DynamoDB.DocumentClient` class](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html)
464+
to call DynamoDB API with native JavaScript types like Array, Number, and Object. It thus simplifies working with items
465+
in Amazon DynamoDB by abstracting away the notion of attribute values.
466+
467+
- In v3, the equivalent [`@aws-sdk/lib-dynamodb`](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_lib_dynamodb.html)
468+
is available. It's similar to normal service clients from v3 SDK, with the difference that it takes a basic DynamoDB
469+
client in its constructor.
470+
471+
Example:
468472

469473
```javascript
470474
import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; // ES6 import
@@ -489,6 +493,38 @@ await ddbDocClient.send(
489493
);
490494
```
491495

496+
### `undefined` values in when marshalling
497+
498+
- In v2 `undefined` values in objects were automatically omitted during the marshalling process to DynamoDB.
499+
500+
- In v3, the default marshalling behavior in @aws-sdk/lib-dynamodb has changed: objects with `undefined` values are no longer omitted. To align with v2's functionality, developers must explicitly set the `removeUndefinedValues` to `true` in the `marshallOptions` of the DynamoDBDocumentClient.
501+
502+
Example:
503+
504+
```js
505+
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
506+
import { DynamoDBDocumentClient, PutCommand } from "@aws-sdk/lib-dynamodb";
507+
508+
const client = new DynamoDBClient({});
509+
510+
// The DynamoDBDocumentClient is configured to handle undefined values properly
511+
const ddbDocClient = DynamoDBDocumentClient.from(client, {
512+
marshallOptions: {
513+
removeUndefinedValues: true
514+
}
515+
});
516+
517+
await ddbDocClient.send(
518+
new PutCommand({
519+
TableName,
520+
Item: {
521+
id: "123",
522+
content: undefined // This value will be automatically omitted
523+
};
524+
})
525+
);
526+
```
527+
492528
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).
493529

494530
## Waiters

0 commit comments

Comments
 (0)