Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

158
Views
Mongoose findOne() with a value higher than a var

So, I've been coding a bot on Discord. But when I tried to make 30 days auto-delete Tags, I been thinking that how do I find a document with a Time Expired Date in miliseconds that higher than current time.

const autoDeleteTag = function () {
 const currentTime = (new Date()).getTime()
 const findTag = tagSchema.findOne({ timeExpired: currentTime })
 if (findTag) return findTag.delete()
}
setInterval(autoDeleteTag(), 100)

But I don't know if this the right code? Because I think sometime it won't delete. Thanks!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you want to compare dates (or values), you can you use the $gt, $lt etc. operators.

For example if you are looking for the older tags than current date:

tagSchema.findOne({ timeExpired: { $lt: currentTime } })
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!