提问人:Keerthana Hemachandran 提问时间:10/31/2023 最后编辑:James ZKeerthana Hemachandran 更新时间:11/1/2023 访问量:27
AWS Dynamoose (v3.2.1) 不允许在表中插入空值
AWS Dynamoose (v3.2.1) does not allow null values to be inserted in the table
问:
我在 Nodejs 应用程序中将 Dynamoose 库从 1.11.1 升级到 3.2.1。为创建 DynamoDB 实例,完成了以下新配置。
const dynamoose = require("dynamoose");
const config = require("../config");
const ddb = new dynamoose.aws.ddb.DynamoDB({
region: config.REGION,
});
dynamoose.aws.ddb.set(ddb);
module.exports = {
dynamoose: dynamoose,
};
我们有一组使用 json crud.js 创建的 CRUD 操作。从数据库中读取(获取)值工作正常。
const _schema = require("./schema");
module.exports = {
create(params) {
const model = new _schema.statusTable(params);
return model.save();
},
delete(key, keyvalue) {
return _schema.statusTable.delete({ key: keyvalue });
},
read(key, value) {
return _schema.statusTable.query(key).eq(value);
},
getcount(key) {
return _schema.statusTable.query(key).counts();
},
};
架构定义如下:
const statusTableSchema = new db.dynamoose.Schema({
'Id': {
type: String,
hashKey: true,
},
status: {
type: String,
},
success_d: {
type: String,
},
fail_d: {
type: String,
}
});
在 Dynamoose 版本 1.11.1 中,创建 CRUD 操作工作正常。但现在,在升级 Dynamoose 库时,当尝试向表中的某个字段添加 null 值时,以下创建 CRUD 操作会引发以下错误。
await crud.create(finalStatus);
ERROR Invoke Error
{
"errorType": "TypeMismatch",
"errorMessage": "Expected fail_d to be of type string, instead found type null.",
"name": "TypeMismatch",
"message": "Expected fail_d to be of type string, instead found type null.",
"stack": [
"TypeMismatch: Expected fail_d to be of type string, instead found type null.",
" at checkTypeFunction (/var/task/node_modules/dynamoose/dist/Item.js:358:27)",
" at Array.map (<anonymous>)",
" at Item.objectFromSchema (/var/task/node_modules/dynamoose/dist/Item.js:383:128)",
" at Item.toDynamo (/var/task/node_modules/dynamoose/dist/Item.js:558:31)",
" at process.processTicksAndRejections (node:internal/process/task_queues:95:5)",
" at async Promise.all (index 0)",
" at async /var/task/node_modules/dynamoose/dist/Item.js:207:17",
" at async Runtime.handler (/var/task/src/index.js:243:5)"
]
}
fail_d是我们尝试通过调用创建 CRUD 操作为其插入 null 值的字段。在架构定义中,为字段声明的数据类型为 String。
使用 NULL 值更新 fail_d 字段需要进行哪些更改?
答: 暂无答案
评论