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

505
Views
Delete specific documents after 7 days

I have made a TTL index on my Schema using:

Schema.index({ expire: 1 }, { expireAfterSeconds: 604800 })

When I want documents to be deleted after the 7 days I use:

Schema.updateMany(query, { $set: { expire: Date.now() } })

Is this the correct way? Is there an easier way to delete specific documents after 7 days? When I want a document to expire do I need to set the TTL index value to a date or could I use a different value?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Yes, you can create a TTL index using (expireAfterSeconds: 7 * 24 * 60 * 60 ). It will help you to automatically delete the documents.

over 4 years ago · Santiago Trujillo 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!