System Information
- Strapi Version: v3.4.1
- Operating System: macOS Catalina Version 10.15.5
- Database: MongoDB v4.2.11
- Node Version: v12.16.3
- NPM Version: v6.14.4
- Yarn Version: v1.22.4
Hi everyone!
When trying to query data from a database, the error “Error: Invalid format, expected a timestamp or an ISO date”.
Steps to reproduce the behavior
- Create a Strapi project using mongoose
- Create a content type with a date field (datetime type)
- Attempt to query data from a database for that type
Model looks like
{
"kind": "collectionType",
"collectionName": "schedulings",
"info": {
"name": "scheduling"
},
"options": {
"increments": true,
"timestamps": true,
"draftAndPublish": false
},
"attributes": {
"startTime": {
"required": true,
"type": "datetime"
},
"endTime": {
"type": "datetime",
"required": true
},
"therapists": {
"collection": "therapists",
"via": "scheduling",
"plugin": ""
}
}
}
Query looks like
const searchResults = await strapi.query('scheduling').find(
{ startTime: { $lte: new Date() } }
);
And result is
Error: Invalid format, expected a timestamp or an ISO date
at parseDateTimeOrTimestamp (/Users/pasha/projects/choosing-therapy/choosing-therapy-admin/node_modules/strapi-utils/lib/parse-type.js:52:11)
at parseType (/Users/pasha/projects/choosing-therapy/choosing-therapy-admin/node_modules/strapi-utils/lib/parse-type.js:93:14)
at castValue (/Users/pasha/projects/choosing-therapy/choosing-therapy-admin/node_modules/strapi-utils/lib/build-query.js:75:10)
at castInput (/Users/pasha/projects/choosing-therapy/choosing-therapy-admin/node_modules/strapi-utils/lib/build-query.js:63:7)
at /Users/pasha/projects/choosing-therapy/choosing-therapy-admin/node_modules/strapi-utils/lib/build-query.js:132:27
at Array.map (<anonymous>)
at normalizeWhereClauses (/Users/pasha/projects/choosing-therapy/choosing-therapy-admin/node_modules/strapi-utils/lib/build-query.js:115:6)
at buildQuery (/Users/pasha/projects/choosing-therapy/choosing-therapy-admin/node_modules/strapi-utils/lib/build-query.js:182:23)
at Object.find (/Users/pasha/projects/choosing-therapy/choosing-therapy-admin/node_modules/strapi-connector-mongoose/lib/queries.js:407:12)
at fn (/Users/pasha/projects/choosing-therapy/choosing-therapy-admin/node_modules/strapi-database/lib/queries/helpers.js:31:54)
at Object.find (/Users/pasha/projects/choosing-therapy/choosing-therapy-admin/node_modules/strapi-database/lib/queries/helpers.js:15:24)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async Object.beforeCreate (/Users/pasha/projects/choosing-therapy/choosing-therapy-admin/api/scheduling/models/scheduling.js:38:29)
at async executeLifecycle (/Users/pasha/projects/choosing-therapy/choosing-therapy-admin/node_modules/strapi-database/lib/utils/lifecycles.js:7:5)
at async Object.create (/Users/pasha/projects/choosing-therapy/choosing-therapy-admin/node_modules/strapi-database/lib/queries/helpers.js:12:3)
at async Object.login (/Users/pasha/projects/choosing-therapy/choosing-therapy-admin/api/test/controllers/test.js:8:21)
Maybe someone had a similar issue?