The value of NUMBER_VALUE cannot be transformed into a String while trying to update the Item

I've encountered a strange issue with DynamoDB where I'm unable to update an item.

Below is the command I'm using:

TableName: 'UserTable',
Key: { UID: { S: 'h4XJj3YRxZiF7TDcGkxAhc' } },
UpdateExpression: 'SET numRatings = :numRatings',
ExpressionAttributeValues: { ':numRatings': { N: 336 } },
ReturnValues: 'UPDATED_NEW'

I've double-checked that the table and key values are correct. The key value for UID in the table is indeed 'h4XJj3YRxZiF7TDcGkxAhc', and the current value of 'numRatings' is 1.

Here's the relevant snippet of my code:

  const params = {
    TableName: process.env.USER_TABLE_NAME!,
    Key: {
      UID: {
        S: UID
      }
    },
    UpdateExpression: 'SET numRatings = :numRatings',
    ExpressionAttributeValues: {
      ':numRatings': { N: numRatings } as unknown as AttributeValue
    },
    ReturnValues: 'UPDATED_NEW'
  } as UpdateItemCommandInput;

  try {
    const result = await dbClient.send(new UpdateItemCommand(params));
...

Despite this, I keep encountering the error:

NUMBER_VALUE cannot be converted to String
, leading me to believe there might be a conversion happening somewhere that I'm missing.

My setup involves TypeScript and AWS-SDK version 3.54.0

If anyone can spot what I'm overlooking, I'd greatly appreciate the help.

https://i.sstatic.net/rzlAL.png

Answer №1

According to the AttributeValue documentation:

When sending numbers to DynamoDB over the network, they are transmitted as strings to ensure compatibility across different languages and libraries. However, despite this, DynamoDB handles them as numerical attributes for calculations.

Therefore, when using the raw DynamoDB client, it is necessary to represent numeric values as type N with the value being a string:

':numRatings': { N: `${numRatings}` }

If you opt for the higher-level DocumentClient, which automatically handles data conversion between JavaScript objects and DynamoDB attribute values, you can simply use:

':numRatings': numRatings

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When you assign the page results from the scrape-it npm to a variable, it will return a Promise with the status of "pending."

I recently downloaded scrape-it from NPM as a dependency and I'm trying to store the results in a variable instead of using a callback function. When I run the code snippet provided in the scrape-it documentation: var myVar = scrapeIt("http://ionicab ...

I need a way to call a function in my Typescript code that will update the total value

I am trying to update my total automatically when the quantity or price changes, but so far nothing is happening. The products in question are as follows: this.products = this.ps.getProduct(); this.form= this.fb.group({ 'total': ...

React Gorgeous Drag and Drop, exchange elements if their values match

Can you help me with a question I have? I am currently using "React beautiful DND" and I need to switch the positions of items. Let me explain the scenario: We have two separate lists that contain different items. If a user drags an item from list A to li ...

Is it possible to retrieve the signature for every method within a class?

Let's consider a scenario where we have a class defined as follows: class Actions { static FooAction = 'foo' as const; someAction1() { return { type: Actions.FooAction, payload: {a: 1, b:2} }} static BarAction = &apos ...

What is the best way to retrieve values from a nested mongodb object?

I am currently working with a Company mongodb structure that looks like this: { "companyName" : "SomeCompany", "Products" : [ { "productId" : "e3rQACssGkfp9zsue", "productCode" : "271102502", "memberPrice" : " ...

What is the best way to transfer an array of AJAX column data to a JavaScript function?

I'm trying to figure out how to pass data from an AJAX Datatable column, which is an array, to a JavaScript function. Below is my script.js: table = $("#table").DataTable({ ajax: { url: "/Object/GetAllDetail&quo ...

Retrieve information in JSON format using AngularJS by fetching data from SQL through PHP

My objective is to retrieve data from a mySql database using PHP, convert it to JSON, and then display it through AngularJS. Although I have successfully completed the steps leading up to this point, I am facing issues with the final step. Below are the de ...

Text element in SVG not displaying title tooltip

Looking for a solution to display a tooltip when hovering over an SVG Text element? Many sources suggest adding a Title element as the first child of the SVG element. This approach seems to work in Chrome, but not in Safari - the primary browser used by mo ...

Implementing data updates in Vue.js within a Mongoose database, along with making API

I've encountered an issue where I need to update a count variable representing the votes each video receives after using GET and POST functions to retrieve and save URLs in my database. Additionally, I'm looking to disable the voting button once ...

Running multiple Karma and Jasmine projects within a single solution efficiently (and the necessity for Jenkins integration)

In our extensive solution, we are managing various projects with Karma & Jasmine Tests. Utilizing Jenkins for continuous integration, our goal is to streamline the process by running the Karma execute command just once. This means eliminating the need to m ...

Halt the execution of any additional code

I have a favor to ask: Character.count({'character.ownerid': msg.author.id}, function (err, count) { if (err) { throw err; } if (count > 3) { err.message = 'Exceeded character limit'; //create error ...

Encountered a TypeScript issue when using React and Slate: The property 'renderElement' is not found on type 'IntrinsicAttributes'

Currently, I am working on mastering Slate by following the steps outlined in this tutorial: Defining Custom Elements. After adapting the code slightly from the tutorial, here is what I have integrated: export default function App() { const renderEleme ...

The React route fails to display until clicked upon

Struggling with integrating React Router into my Electron desktop app for navigation. During debugging, I realized that the login component, which doesn't use routers, transitions smoothly to a component with a router. However, this new component fail ...

Issues with clickable links within a table cell

I am facing an issue with a table where rows <tr> are generated dynamically by a PHP loop. I have transformed the entire row into a link, but the problem arises when there is an <input type="checkbox"> within the row. Whenever I check the check ...

Displaying a meager 0.5% on the BootStrap progress indicator

Utilizing the bootstrap progress bar to display the percentage of a person's miles covered out of a total of 23,872 miles. Take user A as an example, they have covered only 5 miles: 5/23872 = 0.00020945 * 100 = 0.02094504 miles. Currently, anything ...

Error TS2322 occurs when attempting to assign a type '{ text: string; }' to a type 'string' while passing a prop

I am facing an issue when attempting to pass a prop of type string to a functional component that is defined in the same file. The error message displayed is: TS2322: Type '{ text: string; }' is not assignable to type 'string'. Despit ...

JavaScript - Utilize HTML input and modify its format

I have been struggling with this problem for a while now. I am in the process of creating a map to display the orbit of a specific satellite using Google Maps JS API. While I have made some progress, I have not been able to pull data from the HTML page as ...

Looking to access the layout details of an HTML element similar to what can be done in Firefox's debugger tool?

I am facing a challenge with a aspx.net grid control where I need to extract the first row's information and copy it into another table using JavaScript. To achieve this, I am attempting to calculate the width of each cell in the first row by accessin ...

Best method for removing CrosshairMove event listener in lightweight charts

As per the documentation, using unsubscribeCrosshairMove allows us to remove a handler that was previously added with subscribeCrosshairMove. Our objective is to use unsubscribe... to eliminate previous handlers before re-subscribing with subscribe... af ...

Accessing global scope variables within callback functions in JavaScript is a common task that can be achieved in a

When it comes to my user registration process, I've encountered an issue const express = require ('express'); const userRouter = express.Router (); userRouter.get ('/', function getUserList (req, res) { let User = require (& ...