dynamoose: [BUG] TypeMismatch: Expected createdAt to be of type date, instead found type object

Summary:

CloudWatch log image

Doc on Dynamodb image

Code sample:

Schema

const dynamoose = require("dynamoose");
const schema = new dynamoose.Schema({
    email: {
        type: String,
        hashKey: true
    },
    github: Object,
    name: String
}, {
    saveUnknown: true,
    timestamps: true
});

module.exports = dynamoose.model('User', schema);

General

const { User } = require('../db');
const user = await User.query('email').eq(email).exec();

Current output and behavior (including stack trace):

Cant query from dynamodb

Expected output and behavior:

I should be able to query from Dynamodb when I pass the pk value

Environment:

Operating System: NA - Lambda Function Operating System Version: NA Node.js version (node -v): v10.19.0 NPM version: (npm -v): 6.14.8 Dynamoose version: 2.3.0

Other:

  • [x ] I have read through the Dynamoose documentation before posting this issue
  • [x ] I have searched through the GitHub issues (including closed issues) and pull requests to ensure this issue has not already been raised before
  • I have searched the internet and Stack Overflow to ensure this issue hasn’t been raised or answered before
  • [x ] I have tested the code provided and am confident it doesn’t work as intended
  • I have filled out all fields above
  • I am running the latest version of Dynamoose

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (8 by maintainers)

Most upvoted comments

@AllanOricil Right now I don’t have enough information to be able to reproduce this and debug it.

Just for context. I ran the following code.

(async () => {
	const dynamoose = require("dynamoose");
	dynamoose.aws.ddb.local();
	const schema = new dynamoose.Schema({
		email: {
			type: String,
			hashKey: true
		},
		github: Object,
		name: String
	}, {
		saveUnknown: true,
		timestamps: true
	});

	const User = dynamoose.model('User', schema);

	await User.create({
		"email": "test@test.com",
		"github": {
			"credentials": {
				"unknown": "unknown"
			},
			"user": {
				"unknown": "unknown"
			}
		}
	});

	console.log("Created user");

	// Not sure what the variable `email` is set to in your original code so I used `"test@test.com"`
	const user = await User.query('email').eq("test@test.com").exec();
	console.log("Query complete");
	console.log(user);
})();

And got the following result:

charliefish@Charlies-MacBook-Pro tmp2 % node index.js
Created user
Query complete
[
  Document {
    createdAt: 2020-11-22T16:23:13.519Z,
    github: { credentials: [Object], user: [Object] },
    email: 'test@test.com',
    updatedAt: 2020-11-22T16:23:13.519Z
  },
  lastKey: undefined,
  count: 1,
  queriedCount: undefined,
  timesQueried: 1,
  populate: [Function: PopulateDocuments],
  toJSON: [Function: documentToJSON]
]

From my perspective, everything is working fine. Please submit an MCVE as described in the contribution guidelines so I can debug this further.