System Information
- Strapi Version: 4.0.0
- Operating System: MacOS
- Database: PostgreSQL
- Node Version: 16.13.0
- NPM Version: 8.1.0
- Yarn Version: 1.22.15
I have a cron job running every minute that is supposed to query one of my models.
The model has a datetime
attribute named game_date
.
I wanted to run a query that returns results with the game_date
that are less than new Date()
For some reason I can’t get this .find()
to work. It is not filtering for anything inside this .find()
, it always returns all results.
What am I doing wrong and how can I get results based on this datetime
with a ‘less than’ or ‘less than equal’ operator?
module.exports = {
"* * * * *": {
task: async ({ strapi }) => {
const today = new Date();
const { results: games } = await strapi.api[
"anon-game"
].services["anon-game"]
.find({
// doesnt work:
// _publicationState: "preview",
// doesnt work:
// published_at_lt: new Date(),
// doesnt work:
// game_date: { _gte: today.toISOString() },
// doesnt work:
game_date_lt: "2022-01-07T15:00:00.000Z",
// doesnt work:
// _limit: 2,
})
.catch((e) => e);
games.forEach(async (game) => {
console.log(game);
});
},
options: {
tz: "Asia/Dhaka",
},
},
};