0

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

  • 2
    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 Jul 29 at 17:17
0

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.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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