I upgraded the Dynamoose library from 1.11.1 to 3.2.1 in my Nodejs application. The following new configuration was done to create DynamoDB instance.
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,
};
We have a set of CRUD operations created using a json crud.js. Reading(Fetching) values from the DB is working fine.
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();
},
};
The schema is defined as follows,
const statusTableSchema = new db.dynamoose.Schema({
'Id': {
type: String,
hashKey: true,
},
status: {
type: String,
},
success_d: {
type: String,
},
fail_d: {
type: String,
}
});
With Dynamoose version 1.11.1 the create CRUD operation was working fine. But now, upon upgrading the Dynamoose library, the below create CRUD operation throws the following error when trying to add null value to one of the fields in the table.
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)"
]
}
The fail_d is the field for which we are trying to insert null value by calling the create CRUD operation. The datatype declared for the field, in schema definition, is String.
what changes are required to update the fail_d field with null values?