I'm not sure that I'm even asking the right question so I hope you guys can point me in the right direction here.

I have a full stack web app which has listings (think eBay, Gumtree, Craigslist) and I want to implement functionality which allows for featured or premium listings.

The best way I thought to implement this would be to enter an isFeatured: true field into the listing in MongoDB along with a featuredStatusExpiresAt: with some timestamp such that when the timer expires, the field isFeatured: changes to false and so when the listings are called, the ones which have expired are no longer called.

I do not know of a way to make the server wait for a timestamp such that after a particular, specific time, it makes changes to the database

Edit: My tech stack is: Node.js, Express and MongoDB

  • 3
    You don't need to do it like that at all. Just store featuredStatusExpiresAt and filter and/or calculate isFeatured based on the time when you respond to a request for the listings.
    – jonrsharpe
    Commented Jul 29, 2020 at 17:17

1 Answer 1


As jonrsharpe commented, an efficient way to implement this feature would just be to store the timestamp for when the listing should expire. Then, when making requests for featured listings, you would query only ones where the expired timestamp has yet to pass.

If for some other reason you need to run commands at a certain time, two options are:

  1. You can do a 1 sec setInterval to check the current time and conditionally do something.
  2. You can make a cron job on your linux/unix system, or task scheduler on Windows, to run a script at a particular time, or time interval.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.