{
    "componentChunkName": "component---src-templates-mdx-content-page-js",
    "path": "/dynamodb-documentclient/",
    "result": {"data":{"mdx":{"body":"var _excluded = [\"components\"];\n\nfunction _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }\n\nfunction _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }\n\nfunction _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }\n\n/* @jsxRuntime classic */\n\n/* @jsx mdx */\nvar _frontmatter = {\n  \"path\": \"/dynamodb-documentclient/\",\n  \"publishedDate\": \"2026-11-20\",\n  \"updatedDate\": \"2026-11-20\",\n  \"metaTitle\": \"DynamoDBDocumentClient in AWS SDK v3: Examples and Setup\",\n  \"metaDescription\": \"Use @aws-sdk/lib-dynamodb with JavaScript and TypeScript. See runnable DynamoDBDocumentClient examples, marshalling options, pagination, and v2 migration.\",\n  \"title\": \"DynamoDBDocumentClient in AWS SDK for JavaScript v3\",\n  \"authorName\": \"Rafal Wilinski\",\n  \"authorLink\": \"https://x.com/rafalwilinski\",\n  \"authorImage\": \"/images/authors/rafal-wilinski.jpg\"\n};\nvar layoutProps = {\n  _frontmatter: _frontmatter\n};\nvar MDXLayout = \"wrapper\";\nreturn function MDXContent(_ref) {\n  var components = _ref.components,\n      props = _objectWithoutProperties(_ref, _excluded);\n\n  return mdx(MDXLayout, _extends({}, layoutProps, props, {\n    components: components,\n    mdxType: \"MDXLayout\"\n  }), mdx(\"p\", null, mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"DynamoDBDocumentClient\"), \" is the AWS SDK for JavaScript v3 client for reading and writing \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/programming-with-javascript.html\"\n  }, \"DynamoDB items as native JavaScript values\"), \". Install \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"@aws-sdk/lib-dynamodb\"), \" and \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"@aws-sdk/client-dynamodb\"), \", wrap a \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"DynamoDBClient\"), \" with \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"DynamoDBDocumentClient.from()\"), \", and pass document commands to \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"client.send()\"), \". The client translates fields such as keys, items, and expression values between plain JavaScript and DynamoDB's typed attribute format.\"), mdx(\"h2\", null, \"Install and configure the document client\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-bash\"\n  }, \"npm install @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb\\n\")), mdx(\"p\", null, \"Save this as \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"client.mjs\"), \". Set \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"DYNAMODB_LOCAL=1\"), \" for the test setup below. For AWS, the base client resolves its \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-region.html\"\n  }, \"Region\"), \" and \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html\"\n  }, \"Node.js credentials\"), \" from the environment or shared AWS configuration. Pass connection settings to \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"DynamoDBClient\"), \" and translation settings as the second argument to \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/migrate-dynamodb-doc-client.html\"\n  }, mdx(\"inlineCode\", {\n    parentName: \"a\"\n  }, \"DynamoDBDocumentClient.from()\")), \".\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-js\"\n  }, \"import { DynamoDBClient } from \\\"@aws-sdk/client-dynamodb\\\"\\nimport { DynamoDBDocumentClient } from \\\"@aws-sdk/lib-dynamodb\\\"\\n\\nconst local = process.env.DYNAMODB_LOCAL === \\\"1\\\"\\n\\nexport const baseClient = new DynamoDBClient(local ? {\\n  region: \\\"us-east-1\\\",\\n  endpoint: \\\"http://localhost:8000\\\",\\n  credentials: { accessKeyId: \\\"local\\\", secretAccessKey: \\\"local\\\" },\\n} : {})\\n\\nexport const docClient = DynamoDBDocumentClient.from(baseClient, {\\n  marshallOptions: { removeUndefinedValues: true },\\n  unmarshallOptions: { wrapNumbers: true },\\n})\\n\\nexport const tableName = \\\"Orders\\\"\\nexport const orderKey = { pk: \\\"CUSTOMER#42\\\", sk: \\\"ORDER#1001\\\" }\\n\")), mdx(\"p\", null, \"The examples share this module and an \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"Orders\"), \" table with String keys \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"pk\"), \" and \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"sk\"), \". Create the table using the Local setup below and start with the Put/Get example. For a broader SDK walkthrough, see \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"/dynamodb-nodejs/\"\n  }, \"DynamoDB with Node.js\"), \".\"), mdx(\"h2\", null, \"Marshalling and unmarshalling options\"), mdx(\"p\", null, \"Marshalling converts JavaScript inputs to DynamoDB attribute values. Unmarshalling converts response attributes back. The \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://github.com/aws/aws-sdk-js-v3/tree/main/lib/lib-dynamodb#configuration\"\n  }, \"AWS package reference\"), \" lists these options.\"), mdx(\"table\", null, mdx(\"thead\", {\n    parentName: \"table\"\n  }, mdx(\"tr\", {\n    parentName: \"thead\"\n  }, mdx(\"th\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"Option\"), mdx(\"th\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"Default on the document client\"), mdx(\"th\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"Effect\"))), mdx(\"tbody\", {\n    parentName: \"table\"\n  }, mdx(\"tr\", {\n    parentName: \"tbody\"\n  }, mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"marshallOptions.removeUndefinedValues\")), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"false\")), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"With \", mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"true\"), \", omits undefined object properties and removes undefined entries from lists and sets. This can shift list indexes. JavaScript \", mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"null\"), \" is stored as DynamoDB \", mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"NULL\"), \".\")), mdx(\"tr\", {\n    parentName: \"tbody\"\n  }, mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"marshallOptions.convertEmptyValues\")), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"false\")), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"With \", mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"true\"), \", turns empty strings, binary values, and sets into \", mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"NULL\"), \". DynamoDB accepts empty strings and binary values in non-key attributes and rejects empty sets.\")), mdx(\"tr\", {\n    parentName: \"tbody\"\n  }, mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"marshallOptions.convertClassInstanceToMap\")), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"false\")), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"With \", mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"true\"), \", marshals a class instance's enumerable properties as a map. Reads return plain objects.\")), mdx(\"tr\", {\n    parentName: \"tbody\"\n  }, mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"marshallOptions.convertTopLevelContainer\")), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"true\")), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"Emits the enclosing \", mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"M\"), \" or \", mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"L\"), \" attribute wrapper for a top-level value passed to the marshaller. Standalone \", mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"marshall()\"), \" defaults to \", mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"false\"), \". Keep the document client default.\")), mdx(\"tr\", {\n    parentName: \"tbody\"\n  }, mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"marshallOptions.allowImpreciseNumbers\")), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"false\")), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"With \", mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"true\"), \", accepts JavaScript numbers beyond the safe integer bounds, which may have already lost precision.\")), mdx(\"tr\", {\n    parentName: \"tbody\"\n  }, mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"unmarshallOptions.wrapNumbers\")), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"false\")), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"With \", mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"true\"), \", returns DynamoDB numbers as \", mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"NumberValue\"), \" instances. A function receives each numeric value as a string so you can supply your own conversion.\")), mdx(\"tr\", {\n    parentName: \"tbody\"\n  }, mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"unmarshallOptions.convertWithoutMapWrapper\")), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"true\")), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"Skips the implicit \", mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"M\"), \" wrapper used by standalone \", mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"unmarshall()\"), \". Keep the document client default.\")))), mdx(\"p\", null, mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"/code-examples/dynamodb-attribute-not-null/\"\n  }, \"An omitted value leaves the attribute absent, while \", mdx(\"inlineCode\", {\n    parentName: \"a\"\n  }, \"NULL\"), \" is a stored value\"), \". Use the \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.NamingRulesDataTypes.html\"\n  }, \"DynamoDB data type rules\"), \" when deciding how to store empty values. For example, turning an empty key into \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"NULL\"), \" still gives DynamoDB an invalid key.\"), mdx(\"h3\", null, \"Preserve large numbers with NumberValue\"), mdx(\"p\", null, \"Give \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://github.com/aws/aws-sdk-js-v3/tree/main/lib/lib-dynamodb#large-numbers-and-numbervalue\"\n  }, mdx(\"inlineCode\", {\n    parentName: \"a\"\n  }, \"NumberValue.from()\")), \" a string to preserve digits that a JavaScript number would round. Use \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"bigint\"), \" for exact integer writes. With the default read conversion, ordinary values become JavaScript numbers and sufficiently large integer values can come back as \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"bigint\"), \". Choose \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"wrapNumbers: true\"), \" if you need exact decimals on reads too.\"), mdx(\"p\", null, \"Run this snippet after creating the order in the \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"PutCommand\"), \" example. The shared client enables \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"wrapNumbers\"), \" so subsequent reads also preserve the decimal. That setting applies to every numeric attribute the client reads.\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-js\"\n  }, \"import { NumberValue, UpdateCommand } from \\\"@aws-sdk/lib-dynamodb\\\"\\nimport { docClient, tableName, orderKey } from \\\"./client.mjs\\\"\\n\\nconst { Attributes } = await docClient.send(new UpdateCommand({\\n  TableName: tableName,\\n  Key: orderKey,\\n  UpdateExpression: \\\"SET rate = :rate\\\",\\n  ExpressionAttributeValues: {\\n    \\\":rate\\\": NumberValue.from(\\\"12345678901234567890.1234\\\"),\\n  },\\n  ReturnValues: \\\"UPDATED_NEW\\\",\\n}))\\nconsole.log(Attributes?.rate.toString()) // 12345678901234567890.1234\\n\")), mdx(\"p\", null, \"For arithmetic, pass \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"NumberValue.toString()\"), \" to a decimal library or use \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"BigInt\"), \" for an integer string. The wrapper preserves the numeric representation for transport. DynamoDB still enforces its \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.NamingRulesDataTypes.html#HowItWorks.DataTypes\"\n  }, \"number precision and range\"), \".\"), mdx(\"h2\", null, \"Document client commands\"), mdx(\"h3\", null, \"PutCommand and GetCommand\"), mdx(\"p\", null, mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_PutItem.html\"\n  }, mdx(\"inlineCode\", {\n    parentName: \"a\"\n  }, \"PutCommand\")), \" replaces an item with the same primary key unless a condition prevents it. Here, \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"attribute_not_exists(pk)\"), \" checks the specific item identified by both key fields. \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_GetItem.html\"\n  }, mdx(\"inlineCode\", {\n    parentName: \"a\"\n  }, \"GetCommand\")), \" uses the full primary key and returns an absent \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"Item\"), \" if the key does not exist. Use \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"ConsistentRead: true\"), \" when the read must reflect a successful write that preceded it.\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-js\"\n  }, \"import { GetCommand, PutCommand } from \\\"@aws-sdk/lib-dynamodb\\\"\\nimport { docClient, tableName, orderKey } from \\\"./client.mjs\\\"\\n\\nawait docClient.send(new PutCommand({\\n  TableName: tableName,\\n  Item: {\\n    ...orderKey,\\n    status: \\\"PENDING\\\",\\n    tags: new Set([\\\"online\\\", \\\"priority\\\"]),\\n    receipt: new Uint8Array([1, 2, 3]),\\n    createdAt: new Date().toISOString(),\\n  },\\n  ConditionExpression: \\\"attribute_not_exists(pk)\\\",\\n}))\\n\\nconst { Item } = await docClient.send(new GetCommand({\\n  TableName: tableName,\\n  Key: orderKey,\\n  ConsistentRead: true,\\n}))\\nconsole.log(Item ?? \\\"Order not found\\\")\\n\")), mdx(\"h3\", null, \"UpdateCommand\"), mdx(\"p\", null, mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_UpdateItem.html\"\n  }, mdx(\"inlineCode\", {\n    parentName: \"a\"\n  }, \"UpdateCommand\")), \" can create a missing item. Add an existence check when you intend to update only an existing order. \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"ExpressionAttributeNames\"), \" aliases attribute names, including \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ReservedWords.html\"\n  }, \"reserved words\"), \" such as \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"status\"), \". \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"ExpressionAttributeValues\"), \" supplies native JavaScript values, and \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"ReturnValues: \\\"ALL_NEW\\\"\"), \" returns the updated item in \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"Attributes\"), \". See the \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"/dynamodb-update-expression/\"\n  }, \"update expression guide\"), \" for nested fields and other update actions.\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-js\"\n  }, \"import { UpdateCommand } from \\\"@aws-sdk/lib-dynamodb\\\"\\nimport { docClient, tableName, orderKey } from \\\"./client.mjs\\\"\\n\\nconst { Attributes } = await docClient.send(new UpdateCommand({\\n  TableName: tableName,\\n  Key: orderKey,\\n  UpdateExpression: \\\"SET #status = :next\\\",\\n  ConditionExpression: \\\"attribute_exists(pk)\\\",\\n  ExpressionAttributeNames: { \\\"#status\\\": \\\"status\\\" },\\n  ExpressionAttributeValues: { \\\":next\\\": \\\"PAID\\\" },\\n  ReturnValues: \\\"ALL_NEW\\\",\\n}))\\nconsole.log(Attributes)\\n\")), mdx(\"h3\", null, \"QueryCommand and ScanCommand\"), mdx(\"p\", null, mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Query.html\"\n  }, mdx(\"inlineCode\", {\n    parentName: \"a\"\n  }, \"QueryCommand\")), \" uses \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"/code-examples/dynamodb-query-items/\"\n  }, \"partition-key equality\"), \" and can narrow the result by sort key. \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Scan.html\"\n  }, mdx(\"inlineCode\", {\n    parentName: \"a\"\n  }, \"ScanCommand\")), \" walks a table or index. It applies a filter after reading items, so filtering does not reduce the read capacity consumed by the scan. These calls each \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"/dynamodb-faq/what-does-dynamodb-query-return/\"\n  }, \"fetch one page\"), \".\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-js\"\n  }, \"import { QueryCommand, ScanCommand } from \\\"@aws-sdk/lib-dynamodb\\\"\\nimport { docClient, tableName, orderKey } from \\\"./client.mjs\\\"\\n\\nconst query = await docClient.send(new QueryCommand({\\n  TableName: tableName,\\n  KeyConditionExpression: \\\"pk = :customer AND begins_with(sk, :prefix)\\\",\\n  ExpressionAttributeValues: {\\n    \\\":customer\\\": orderKey.pk,\\n    \\\":prefix\\\": \\\"ORDER#\\\",\\n  },\\n}))\\nconsole.log(query.Items, query.LastEvaluatedKey)\\n\\nconst scan = await docClient.send(new ScanCommand({\\n  TableName: tableName,\\n  FilterExpression: \\\"#status = :paid\\\",\\n  ExpressionAttributeNames: { \\\"#status\\\": \\\"status\\\" },\\n  ExpressionAttributeValues: { \\\":paid\\\": \\\"PAID\\\" },\\n}))\\nconsole.log(scan.Items, scan.LastEvaluatedKey)\\n\")), mdx(\"h3\", null, \"BatchGetCommand and BatchWriteCommand\"), mdx(\"p\", null, mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchGetItem.html\"\n  }, mdx(\"inlineCode\", {\n    parentName: \"a\"\n  }, \"BatchGetCommand\")), \" accepts up to 100 keys per call. Responses can arrive in any order and omit missing items. Identify results by their primary keys and \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"/code-examples/dynamodb-batchgetitem/\"\n  }, \"retry only \", mdx(\"inlineCode\", {\n    parentName: \"a\"\n  }, \"UnprocessedKeys\")), \". \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchWriteItem.html\"\n  }, mdx(\"inlineCode\", {\n    parentName: \"a\"\n  }, \"BatchWriteCommand\")), \" accepts up to 25 puts or deletes per call. Puts overwrite existing items, and the batch has no per-item conditions or atomic commit. Retry only \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"UnprocessedItems\"), \" with backoff.\"), mdx(\"p\", null, \"The example batches use one table. If a response still contains pending work after the last retry, the thrown error carries it in \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"cause\"), \". For reads it also carries the items already collected.\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-js\"\n  }, \"import { setTimeout as sleep } from \\\"node:timers/promises\\\"\\nimport { BatchGetCommand, BatchWriteCommand } from \\\"@aws-sdk/lib-dynamodb\\\"\\nimport { docClient, tableName, orderKey } from \\\"./client.mjs\\\"\\n\\nconst secondKey = { pk: orderKey.pk, sk: \\\"ORDER#1002\\\" }\\n\\nasync function retryBatches(pending, sendBatch) {\\n  const maxRetries = 5\\n  for (let attempt = 0; attempt <= maxRetries; attempt += 1) {\\n    if (attempt > 0) await sleep(Math.random() * 50 * 2 ** (attempt - 1))\\n    pending = await sendBatch(pending)\\n    if (Object.keys(pending).length === 0) return\\n  }\\n  throw new Error(\\\"DynamoDB batch retries exhausted\\\", { cause: pending })\\n}\\n\\nawait retryBatches({\\n  [tableName]: [\\n    { PutRequest: { Item: { ...secondKey, status: \\\"PENDING\\\" } } },\\n  ],\\n}, async (requestItems) => {\\n  const { UnprocessedItems } = await docClient.send(new BatchWriteCommand({\\n    RequestItems: requestItems,\\n  }))\\n  return UnprocessedItems ?? {}\\n})\\n\\nconst orders = []\\nawait retryBatches({\\n  [tableName]: { Keys: [orderKey, secondKey], ConsistentRead: true },\\n}, async (requestItems) => {\\n  const { Responses, UnprocessedKeys } = await docClient.send(new BatchGetCommand({\\n    RequestItems: requestItems,\\n  }))\\n  orders.push(...(Responses?.[tableName] ?? []))\\n  return UnprocessedKeys ?? {}\\n}).catch((error) => {\\n  error.items = orders\\n  throw error\\n})\\nconsole.log(orders)\\n\")), mdx(\"h3\", null, \"TransactWriteCommand\"), mdx(\"p\", null, mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_TransactWriteItems.html\"\n  }, mdx(\"inlineCode\", {\n    parentName: \"a\"\n  }, \"TransactWriteCommand\")), \" makes changes to distinct items atomically. This order can ship only while it is paid, and the shipment marker must be new. Place the status check on the update itself because a transaction can target a particular item only once. The \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"/dynamodb-transactions/\"\n  }, \"transactions guide\"), \" covers when to use transactional reads and writes.\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-js\"\n  }, \"import { TransactWriteCommand } from \\\"@aws-sdk/lib-dynamodb\\\"\\nimport { docClient, tableName, orderKey } from \\\"./client.mjs\\\"\\n\\nawait docClient.send(new TransactWriteCommand({\\n  TransactItems: [\\n    {\\n      Update: {\\n        TableName: tableName,\\n        Key: orderKey,\\n        UpdateExpression: \\\"SET #status = :shipped\\\",\\n        ConditionExpression: \\\"#status = :paid\\\",\\n        ExpressionAttributeNames: { \\\"#status\\\": \\\"status\\\" },\\n        ExpressionAttributeValues: { \\\":paid\\\": \\\"PAID\\\", \\\":shipped\\\": \\\"SHIPPED\\\" },\\n      },\\n    },\\n    {\\n      Put: {\\n        TableName: tableName,\\n        Item: { pk: orderKey.pk, sk: \\\"SHIPMENT#1001\\\", orderId: orderKey.sk },\\n        ConditionExpression: \\\"attribute_not_exists(pk)\\\",\\n      },\\n    },\\n  ],\\n}))\\n\")), mdx(\"h3\", null, \"ExecuteStatementCommand with PartiQL\"), mdx(\"p\", null, \"Import \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"ExecuteStatementCommand\"), \" from \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"@aws-sdk/lib-dynamodb\"), \" to pass JavaScript values in \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"Parameters\"), \". Bind values with \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"?\"), \" and include partition-key equality in the \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ql-reference.select.html\"\n  }, mdx(\"inlineCode\", {\n    parentName: \"a\"\n  }, \"SELECT\"), \" statement\"), \" to avoid a full table scan. Follow \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_ExecuteStatement.html\"\n  }, mdx(\"inlineCode\", {\n    parentName: \"a\"\n  }, \"NextToken\")), \" when the response supplies it. See the \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"/dynamodb-partiql/\"\n  }, \"PartiQL guide\"), \" for other statements.\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-js\"\n  }, \"import { ExecuteStatementCommand } from \\\"@aws-sdk/lib-dynamodb\\\"\\nimport { docClient, orderKey } from \\\"./client.mjs\\\"\\n\\nlet nextToken\\ndo {\\n  const page = await docClient.send(new ExecuteStatementCommand({\\n    Statement: 'SELECT * FROM \\\"Orders\\\" WHERE pk = ? AND sk = ?',\\n    Parameters: [orderKey.pk, orderKey.sk],\\n    NextToken: nextToken,\\n  }))\\n  console.log(page.Items)\\n  nextToken = page.NextToken\\n} while (nextToken)\\n\")), mdx(\"h3\", null, \"DeleteCommand\"), mdx(\"p\", null, mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_DeleteItem.html\"\n  }, mdx(\"inlineCode\", {\n    parentName: \"a\"\n  }, \"DeleteCommand\")), \" deletes one item by primary key. \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"ReturnValues: \\\"ALL_OLD\\\"\"), \" returns its pre-delete attributes if it existed. This example deletes the second order created by the batch write.\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-js\"\n  }, \"import { DeleteCommand } from \\\"@aws-sdk/lib-dynamodb\\\"\\nimport { docClient, tableName, orderKey } from \\\"./client.mjs\\\"\\n\\nconst { Attributes } = await docClient.send(new DeleteCommand({\\n  TableName: tableName,\\n  Key: { pk: orderKey.pk, sk: \\\"ORDER#1002\\\" },\\n  ReturnValues: \\\"ALL_OLD\\\",\\n}))\\nconsole.log(Attributes)\\n\")), mdx(\"h2\", null, \"Paginate with paginateQuery and paginateScan\"), mdx(\"p\", null, \"Both \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://docs.aws.amazon.com/code-library/latest/ug/javascript_3_dynamodb_code_examples.html\"\n  }, \"SDK paginators\"), \" return async iterators over pages. They pass each \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"LastEvaluatedKey\"), \" as the next request's \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"ExclusiveStartKey\"), \". A \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.Pagination.html\"\n  }, \"filtered page\"), \" can contain zero matches and still have a continuation key. \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"pageSize\"), \" limits evaluated items per request, so it does not guarantee that many matches. See \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"/dynamodb-pagination/\"\n  }, \"DynamoDB pagination\"), \" for manual cursors.\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-js\"\n  }, \"import { paginateQuery, paginateScan } from \\\"@aws-sdk/lib-dynamodb\\\"\\nimport { docClient, tableName, orderKey } from \\\"./client.mjs\\\"\\n\\nconst config = { client: docClient, pageSize: 1 }\\nfor await (const page of paginateQuery(config, {\\n  TableName: tableName,\\n  KeyConditionExpression: \\\"pk = :customer AND begins_with(sk, :prefix)\\\",\\n  ExpressionAttributeValues: { \\\":customer\\\": orderKey.pk, \\\":prefix\\\": \\\"ORDER#\\\" },\\n})) {\\n  console.log(page.Items ?? [])\\n}\\n\\nfor await (const page of paginateScan(config, { TableName: tableName })) {\\n  console.log(page.Items ?? [])\\n}\\n\")), mdx(\"h2\", null, \"Sets, binary, dates, and conversion boundaries\"), mdx(\"ul\", null, mdx(\"li\", {\n    parentName: \"ul\"\n  }, mdx(\"strong\", {\n    parentName: \"li\"\n  }, \"Sets.\"), \" Use \", mdx(\"inlineCode\", {\n    parentName: \"li\"\n  }, \"new Set([\\\"online\\\", \\\"priority\\\"])\"), \" for a String Set. Arrays become lists. Keep set members of the same DynamoDB scalar type and treat the returned set as unordered.\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, mdx(\"strong\", {\n    parentName: \"li\"\n  }, \"Binary.\"), \" Pass \", mdx(\"inlineCode\", {\n    parentName: \"li\"\n  }, \"Uint8Array\"), \" or Node.js \", mdx(\"inlineCode\", {\n    parentName: \"li\"\n  }, \"Buffer\"), \" for binary data, or a set of byte arrays for a Binary Set. Decode a base64 string to bytes before passing it in if the attribute should have DynamoDB type \", mdx(\"inlineCode\", {\n    parentName: \"li\"\n  }, \"B\"), \".\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, mdx(\"strong\", {\n    parentName: \"li\"\n  }, \"Dates.\"), \" Store \", mdx(\"inlineCode\", {\n    parentName: \"li\"\n  }, \"date.toISOString()\"), \" for a readable timestamp or a number for epoch time. Reconstruct the \", mdx(\"inlineCode\", {\n    parentName: \"li\"\n  }, \"Date\"), \" in your application. DynamoDB has no Date type.\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, mdx(\"strong\", {\n    parentName: \"li\"\n  }, \"Typed maps and expressions.\"), \" Supply \", mdx(\"inlineCode\", {\n    parentName: \"li\"\n  }, \"{ pk: \\\"CUSTOMER#42\\\" }\"), \" as a document key. The low-level client expects \", mdx(\"inlineCode\", {\n    parentName: \"li\"\n  }, \"{ pk: { S: \\\"CUSTOMER#42\\\" } }\"), \". Passing the second form to a document command marshals the nested object as a map. Expression text and name aliases are passed through, so write the expressions and supply the matching values yourself.\")), mdx(\"p\", null, \"See the \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://github.com/aws/aws-sdk-js-v3/tree/main/lib/lib-dynamodb#marshalling-input-and-unmarshalling-response-data\"\n  }, \"AWS SDK type mappings\"), \" and \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.NamingRulesDataTypes.html\"\n  }, \"DynamoDB data types\"), \" for the supported representations.\"), mdx(\"h2\", null, \"Migrate from AWS.DynamoDB.DocumentClient v2\"), mdx(\"p\", null, \"Replace \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"await v2.get(params).promise()\"), \" with \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"await docClient.send(new GetCommand(params))\"), \". The \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html\"\n  }, \"v2 methods\"), \" returned request objects. The \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/migrating.html\"\n  }, \"v3 send call\"), \" already returns a promise.\"), mdx(\"table\", null, mdx(\"thead\", {\n    parentName: \"table\"\n  }, mdx(\"tr\", {\n    parentName: \"thead\"\n  }, mdx(\"th\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"v2 DocumentClient method\"), mdx(\"th\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"v3 command passed to \", mdx(\"inlineCode\", {\n    parentName: \"th\"\n  }, \"send()\")))), mdx(\"tbody\", {\n    parentName: \"table\"\n  }, mdx(\"tr\", {\n    parentName: \"tbody\"\n  }, mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"get(params)\")), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"GetCommand\"))), mdx(\"tr\", {\n    parentName: \"tbody\"\n  }, mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"put(params)\")), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"PutCommand\"))), mdx(\"tr\", {\n    parentName: \"tbody\"\n  }, mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"update(params)\")), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"UpdateCommand\"))), mdx(\"tr\", {\n    parentName: \"tbody\"\n  }, mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"delete(params)\")), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"DeleteCommand\"))), mdx(\"tr\", {\n    parentName: \"tbody\"\n  }, mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"query(params)\")), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"QueryCommand\"))), mdx(\"tr\", {\n    parentName: \"tbody\"\n  }, mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"scan(params)\")), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"ScanCommand\"))), mdx(\"tr\", {\n    parentName: \"tbody\"\n  }, mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"batchGet(params)\")), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"BatchGetCommand\"))), mdx(\"tr\", {\n    parentName: \"tbody\"\n  }, mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"batchWrite(params)\")), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"BatchWriteCommand\"))), mdx(\"tr\", {\n    parentName: \"tbody\"\n  }, mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"transactGet(params)\")), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"TransactGetCommand\"))), mdx(\"tr\", {\n    parentName: \"tbody\"\n  }, mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"transactWrite(params)\")), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, mdx(\"inlineCode\", {\n    parentName: \"td\"\n  }, \"TransactWriteCommand\"))))), mdx(\"p\", null, \"Use native \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"Set\"), \" in place of v2's \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"createSet()\"), \". Set \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"marshallOptions.removeUndefinedValues: true\"), \" to preserve v2's omission of undefined values. Recheck any code that reads numeric wrappers or serializes sets to JSON. \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/migrate-dynamodb-doc-client.html\"\n  }, \"AWS's DocumentClient migration notes\"), \" explain the undefined-value change.\"), mdx(\"h2\", null, \"TypeScript typing tips\"), mdx(\"p\", null, \"Import command input and output types from \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"@aws-sdk/lib-dynamodb\"), \". The \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-lib-dynamodb/Class/GetCommand/\"\n  }, \"SDK's GetCommand types\"), \" describe supported attribute values and leave \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"Item\"), \" optional. Validate the fields your application needs before treating a stored item as an application type. This matters when older items or projections may be missing fields.\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-ts\"\n  }, \"import { GetCommand, type GetCommandInput } from \\\"@aws-sdk/lib-dynamodb\\\"\\nimport type { DynamoDBDocumentClient } from \\\"@aws-sdk/lib-dynamodb\\\"\\n\\ntype OrderKey = { pk: string; sk: string }\\n\\nexport async function getOrderStatus(\\n  client: DynamoDBDocumentClient,\\n  key: OrderKey,\\n): Promise<string | undefined> {\\n  const input = { TableName: \\\"Orders\\\", Key: key } satisfies GetCommandInput\\n  const { Item } = await client.send(new GetCommand(input))\\n  if (!Item) return undefined\\n  if (typeof Item.status !== \\\"string\\\") throw new Error(\\\"Order status is invalid\\\")\\n  return Item.status\\n}\\n\")), mdx(\"p\", null, \"If you enable \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"wrapNumbers\"), \", model numeric fields as \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"NumberValue\"), \" or validate the output of your custom wrapper. A type assertion cannot change the SDK's runtime conversion.\"), mdx(\"h2\", null, \"Common errors\"), mdx(\"p\", null, mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"/dynamodb-errors/aws-dynamodb-documentclient-is-not-a-constructor/\"\n  }, \"Constructor error reference for SDK v2\")), mdx(\"ul\", null, mdx(\"li\", {\n    parentName: \"ul\"\n  }, mdx(\"strong\", {\n    parentName: \"li\"\n  }, \"DocumentClient is not a constructor.\"), \" Import \", mdx(\"inlineCode\", {\n    parentName: \"li\"\n  }, \"DynamoDBDocumentClient\"), \" from \", mdx(\"inlineCode\", {\n    parentName: \"li\"\n  }, \"@aws-sdk/lib-dynamodb\"), \" and call \", mdx(\"inlineCode\", {\n    parentName: \"li\"\n  }, \".from(baseClient)\"), \". The \", mdx(\"inlineCode\", {\n    parentName: \"li\"\n  }, \"new AWS.DynamoDB.DocumentClient()\"), \" spelling belongs to \", mdx(\"a\", {\n    parentName: \"li\",\n    \"href\": \"https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/migrate-dynamodb-doc-client.html\"\n  }, \"SDK v2\"), \".\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, mdx(\"strong\", {\n    parentName: \"li\"\n  }, mdx(\"a\", {\n    parentName: \"strong\",\n    \"href\": \"/dynamodb-errors/dynamodb-key-element-does-not-match-the-schema/\"\n  }, \"The provided key element does not match the schema.\")), \" Check the key names and types and include both components of a \", mdx(\"a\", {\n    parentName: \"li\",\n    \"href\": \"https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_GetItem.html\"\n  }, \"composite primary key\"), \". Use native values with document commands.\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, mdx(\"strong\", {\n    parentName: \"li\"\n  }, \"ConditionalCheckFailedException.\"), \" The write's condition evaluated to false. A second run of the conditional put above gives this error for the existing order. Handle it as a conflict and check the current item state before deciding whether to retry. See \", mdx(\"a\", {\n    parentName: \"li\",\n    \"href\": \"/dynamodb-errors/dynamodb-conditionalcheckfailedexception/\"\n  }, \"condition failure troubleshooting\"), \" and the \", mdx(\"a\", {\n    parentName: \"li\",\n    \"href\": \"https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_PutItem.html#API_PutItem_Errors\"\n  }, \"AWS PutItem error reference\"), \".\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, mdx(\"strong\", {\n    parentName: \"li\"\n  }, \"Marshalling fails on undefined or a large number.\"), \" Omit undefined fields or opt into \", mdx(\"inlineCode\", {\n    parentName: \"li\"\n  }, \"removeUndefinedValues\"), \". Use an exact string with \", mdx(\"inlineCode\", {\n    parentName: \"li\"\n  }, \"NumberValue.from()\"), \" if a numeric input exceeds JavaScript's safe precision. Use \", mdx(\"inlineCode\", {\n    parentName: \"li\"\n  }, \"REMOVE\"), \" in an update expression to delete a stored attribute explicitly. See the \", mdx(\"a\", {\n    parentName: \"li\",\n    \"href\": \"https://github.com/aws/aws-sdk-js-v3/tree/main/lib/lib-dynamodb#configuration\"\n  }, \"SDK conversion options\"), \" and \", mdx(\"a\", {\n    parentName: \"li\",\n    \"href\": \"https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html\"\n  }, \"DynamoDB update expressions\"), \".\")), mdx(\"h2\", null, \"Test against DynamoDB Local\"), mdx(\"p\", null, \"Start \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.DownloadingAndRunning.html\"\n  }, \"DynamoDB Local in Docker\"), \" and publish its port on the loopback interface. The in-memory database is reset when the container stops.\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-bash\"\n  }, \"docker run -d --rm --name dynamodb-local -p 127.0.0.1:8000:8000 \\\\\\n  amazon/dynamodb-local:latest -jar DynamoDBLocal.jar -inMemory -sharedDb -disableTelemetry\\n\")), mdx(\"p\", null, \"Save this as \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"create-table.mjs\"), \". \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"CreateTableCommand\"), \" belongs to the \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/dynamodb/\"\n  }, \"base client\"), \" because it manages table definitions.\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-js\"\n  }, \"import { CreateTableCommand, waitUntilTableExists } from \\\"@aws-sdk/client-dynamodb\\\"\\nimport { baseClient, tableName } from \\\"./client.mjs\\\"\\n\\nif (process.env.DYNAMODB_LOCAL !== \\\"1\\\") throw new Error(\\\"Set DYNAMODB_LOCAL=1\\\")\\n\\nawait baseClient.send(new CreateTableCommand({\\n  TableName: tableName,\\n  BillingMode: \\\"PAY_PER_REQUEST\\\",\\n  AttributeDefinitions: [\\n    { AttributeName: \\\"pk\\\", AttributeType: \\\"S\\\" },\\n    { AttributeName: \\\"sk\\\", AttributeType: \\\"S\\\" },\\n  ],\\n  KeySchema: [\\n    { AttributeName: \\\"pk\\\", KeyType: \\\"HASH\\\" },\\n    { AttributeName: \\\"sk\\\", KeyType: \\\"RANGE\\\" },\\n  ],\\n}))\\nawait waitUntilTableExists({ client: baseClient, maxWaitTime: 30 }, {\\n  TableName: tableName,\\n})\\n\")), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-bash\"\n  }, \"export DYNAMODB_LOCAL=1\\nnode create-table.mjs\\n\")), mdx(\"p\", null, \"Save each JavaScript example in its own \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \".mjs\"), \" file alongside \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"client.mjs\"), \" and run it with Node.js in the same shell. Begin with Put/Get, then run the precision example. Verify that Update returns \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"PAID\"), \", the transaction changes it to \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"SHIPPED\"), \", and the delete returns the second order. For a multi-page query, run the paginator after the batch write and before deleting the second order. \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.UsageNotes.html\"\n  }, \"Local usage notes\"), \" explain that the emulator ignores provisioned throughput. Test pending-work handling with a stub response that contains \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"UnprocessedItems\"), \" or \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"UnprocessedKeys\"), \".\"), mdx(\"p\", null, \"Stop the disposable local database with \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"docker stop dynamodb-local\"), \".\"), mdx(FAQ, {\n    questions: [{\n      question: \"Which package exports DynamoDBDocumentClient?\",\n      answer: \"Import DynamoDBDocumentClient and document commands from @aws-sdk/lib-dynamodb. Import the base DynamoDBClient from @aws-sdk/client-dynamodb.\"\n    }, {\n      question: \"Does DynamoDBDocumentClient skip undefined values?\",\n      answer: \"Set removeUndefinedValues to true in marshallOptions to omit undefined values from objects, lists, and sets. Null is stored as a DynamoDB NULL attribute.\"\n    }, {\n      question: \"How do I read a DynamoDB number without losing precision?\",\n      answer: \"Set wrapNumbers to true in unmarshallOptions and call toString on the resulting NumberValue. For writes, pass the original numeric string to NumberValue.from before any JavaScript number conversion.\"\n    }, {\n      question: \"How do I fetch every page with DynamoDBDocumentClient?\",\n      answer: \"Use paginateQuery or paginateScan from @aws-sdk/lib-dynamodb with a for await loop. A filtered page can be empty while there are more pages to evaluate.\"\n    }, {\n      question: \"Can DynamoDBDocumentClient connect to DynamoDB Local?\",\n      answer: \"Yes. Configure the base DynamoDBClient with the local endpoint, a Region, and dummy credentials, then wrap it with DynamoDBDocumentClient.from.\"\n    }],\n    mdxType: \"FAQ\"\n  }));\n}\n;\nMDXContent.isMDXComponent = true;","frontmatter":{"publishedDate":"2026-11-20","updatedDate":"2026-11-20","path":"/dynamodb-documentclient/","metaTitle":"DynamoDBDocumentClient in AWS SDK v3: Examples and Setup","metaDescription":"Use @aws-sdk/lib-dynamodb with JavaScript and TypeScript. See runnable DynamoDBDocumentClient examples, marshalling options, pagination, and v2 migration.","title":"DynamoDBDocumentClient in AWS SDK for JavaScript v3","authorName":"Rafal Wilinski","authorLink":"https://x.com/rafalwilinski","authorImage":"/images/authors/rafal-wilinski.jpg","image":null}}},"pageContext":{}},
    "staticQueryHashes": ["3649515864"]}