gpt4 book ai didi

Dynamodb update (Cannot read properties of undefined (reading '0'))(Dynamodb更新(无法读取未定义的属性(读取“0”)))

转载 作者:bug小助手 更新时间:2023-10-22 15:47:03 30 4
gpt4 key购买 nike



Params:

参数:


 {
"TableName": "xxxxxxx",
"Key": {
"userId": {
"S": "test"
}
},
"UpdateExpression": "SET sent.#assignmentType = :newHomeworks",
"ExpressionAttributeNames": {
"#assignmentType": "books"
},
"ExpressionAttributeValues": {
":newHomeworks": [
{
"M": {
"homeworkId": {
"S": "homework"
},
"userIds": {
"L": [
{
"S": "test1"
},
{
"S": "test2"
}
]
}
}
}
]
},
"ReturnValues": "UPDATED_NEW"
}

do you know why I'm getting this error? It is when I'm trying to update the item like that.
newHomeworks ormat is wrong? it should be an array of objects.Thank you!

你知道我为什么会犯这个错误吗?这是当我试图像那样更新项目时。newHomeworks格式错误?它应该是一个对象数组。非常感谢。


I have inserted only the broken code,It's breaking after the "Update params" log, I tried to send the params in many ways but I cannot find an explanation, I don't know why I get this error.
I don't think it's something wrong in updateHomeworkTable because it's working in other cases, only here it is breaking.
code:

我只插入了损坏的代码,在“更新params”日志之后它就坏了,我试图通过多种方式发送params,但我找不到解释,我不知道为什么我会出现这个错误。我不认为updateHomeworkTable有什么问题,因为它在其他情况下也能工作,只是在这里它坏了。代码:


async assignedHomework(
userId: string,
studentIds: any,
homework: any,
assignmentType: string
) {
const userHomeworks = await this.reader.getUserFromDb(userId);
if (userHomeworks?.sent) {
if (userHomeworks.sent[assignmentType]) {
for (const homeworkObj of userHomeworks.sent[assignmentType]) {
if (homeworkObj.homeworkId === homework) {
homeworkObj.userIds = Array.from(
new Set([...homeworkObj.userIds, ...studentIds])
);

const updateExpression = "SET sent.#assignmentType = :newHomeworks";

// Define attribute names and values
const expressionAttributeNames = {
"#assignmentType": assignmentType,
};
this.logger.debug("parameters", userHomeworks.sent[assignmentType]);

// AICI NEW HOMEWORKS NU ARE TREBUII SA FIE ALTFEL?
const expressionAttributeValues = {
":newHomeworks": marshall(userHomeworks.sent[assignmentType]),
};
this.logger.debug(
"parameters after update",
marshall(userHomeworks.sent[assignmentType])
);
return await updateHomeworkTable(
this.tableName,
userId.toString(),
updateExpression,
expressionAttributeNames,
expressionAttributeValues,
this.instance,
this.logger
);
}
}
const updateExpression =
"SET sent.#assignmentType = list_append(if_not_exists(sent.#assignmentType, :emptyList), :newHomework)";

// Define attribute names and values
const expressionAttributeNames = {
"#assignmentType": assignmentType,
};

const expressionAttributeValues = {
":newHomework": {
L: [
{
M: {
homeworkId: { S: homework },
userIds: { L: studentIds.map((id: string) => ({ S: id })) },
},
},
],
},
":emptyList": { L: [] },
};
return await updateHomeworkTable(
this.tableName,
userId.toString(),
updateExpression,
expressionAttributeNames,
expressionAttributeValues,
this.instance,
this.logger
);
} else {
}
}
const updateHomeworkTable = async (
tableName: string,
userId: string,
updateExpression: string,
expressionAttributeNames: any,
expressionAttributeValues: any,
instance: any,
logger: any
) => {
// Create UpdateItem command input
const params: UpdateItemCommandInput = {
TableName: tableName,
Key: {
userId: { S: userId },
},
UpdateExpression: updateExpression,
ExpressionAttributeNames: expressionAttributeNames,
ExpressionAttributeValues: expressionAttributeValues,
ReturnValues: "UPDATED_NEW",
};

logger.debug("Update params", params);
await instance.send(new UpdateItemCommand(params));
logger.debug("Update finished");
};

Update...
it shouldn't be something here ?
Like ":newHomeworks":{L:[]}?

使现代化这不应该是什么东西吗?像“:newHomeworks”:{L:[]}?


更多回答

I'm not an expert in nodejs, so I might be missing something (and don't understand what this error message refers to...), but isn't userIds: { L: studentIds.map((id: string) => ({ S: id })) }, wrong? An "L" says what follows should be a list, but it seems what follows is a map, not a list. Maybe you meant a list of maps?

我不是nodejs方面的专家,所以我可能遗漏了一些东西(不明白这个错误消息指的是什么…),但userIds:{L:studentIds.map((id:string)=>({S:id}))}不是吗?一个“L”表示后面应该是一个列表,但后面似乎是一张地图,而不是一个列表。也许你的意思是地图列表?

Please log and share the params of in your function.

请登录并在您的函数中共享的参数。

The first piece of code represent the params.

第一段代码表示参数。

And I think it is correct like this Nadav :"userIds": { "L": [ { "S": "test1" }, { "S": "test2" } ]

我认为这是正确的,Nadav:“userIds”:{“L”:[{“S”:“test1”},{“S”:“test 2”}]

优秀答案推荐
更多回答

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com