[英]DynamoDB throwing undefined values error despite being able to write to DB using different array to PUT to DB
I have a method that's making a call to a table with the following schema: userId: string |我有一个方法调用具有以下架构的表:userId: string | sessionId: string |
sessionId: 字符串 | orders: list Here's the following code:
orders: list 下面是代码:
const marshallOptions = {
convertEmptyValues: false,
removeUndefinedValues: false,
convertClassInstanceToMap: false,
};
const unmarshallOptions = {
wrapNumbers: false,
};
const translateConfig = { marshallOptions, unmarshallOptions };
const client: DynamoDBClient = new DynamoDBClient({});
const dynamo: DynamoDBDocument = DynamoDBDocument.from(client, translateConfig);
async function handleOrder(event: APIGatewayProxyEventV2): Promise<string> {
let req: any = JSON.parse(String(event?.body));
// Get student's orders
let studentOrderSubmissions: any = await dynamo.send(new GetCommand({
TableName: orderBook,
Key: {
userId: req.userId,
sessionId: sessionIdPlaceholder
}
}))
let studentOrders: any = studentOrderSubmissions.Item?.orders;
const orderInfo: OrderInfo = {
orderNumber: req.orderNumber,
userId: req.userId,
price: req.price,
position: req.position,
isLong: req.isLong,
isBuy: req.isBuy,
quantity: req.quantity,
closedOut: req.closedOut
}
studentOrders.push(orderInfo);
const params = {
TableName: orderBook,
Item: {
userId: req.userId,
sessionId: req.sessionId,
orders: studentOrders
}
};
await dynamo.put(params, function(err: any, data: any) {
if (err) {
console.log("Error", err);
}
else {
console.log("Success", data);
}
});
When modifying the studentOrders array pushing a new student order into it, after trying to PUT the changes into DynamoDb into the OrderBook table, I always get the following error: Pass options.removeUndefinedValues=true to remove undefined values from map/array/set.
在修改 studentOrders 数组以将新的学生订单推入其中时,在尝试将更改放入 DynamoDb 到 OrderBook 表中后,我总是收到以下错误:
Pass options.removeUndefinedValues=true to remove undefined values from map/array/set.
EVEN after setting marshall options.removeUndefinedValues to false (despite it by default being false).即使在将 marshall options.removeUndefinedValues 设置为 false 之后(尽管它默认为 false)。
When I create a new array with the following code:当我使用以下代码创建一个新数组时:
const testArray: any = [];
testArray.push(orderInfo);
and replace studentOrders with testArray, DynamoDB saves the data and doesn't throw an error.并将 studentOrders 替换为 testArray,DynamoDB 会保存数据并且不会抛出错误。 Is this because DynamoDB doesn't allow you to pass in an array from itself?
这是因为 DynamoDB 不允许您从自身传入数组吗? How would one update a list attribute in a table then?
那么如何更新表中的列表属性呢? If I can't use
put
or PutCommand
that leaves me with the query options and writing a new query but I figured I'd ask more experienced people first if they've ever run into this problem.如果我不能使用
put
或PutCommand
这会给我留下查询选项并编写一个新查询,但我想我会先询问更有经验的人是否遇到过这个问题。
Found out what the issue was.找出问题所在。 My object wasn't undefined.
我的 object 不是未定义的。 What was undefined was my sort key.
未定义的是我的排序键。 It was throwing an error letting me know one of my values being passed into the parameters was undefined but didn't tell me which one specifically: With that being said the error was here:
它抛出了一个错误,让我知道我传递给参数的值之一是未定义的,但没有告诉我具体是哪一个:话虽如此,错误在这里:
Item: {
userId: req.userId,
sessionId: req.sessionId,
orders: studentOrders
}
I never defined req.sessionId, SO THAT was what was causing the freak out.我从未定义过 req.sessionId,所以这就是导致异常的原因。 It really should've been cannot pass undefined KEY rather than just say that you can't pass an undefined value.
它真的应该是 cannot pass undefined KEY 而不是仅仅说你不能传递一个未定义的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.