'MongoDB TTL deleting documents later then specified delay time

I am trying to delete a document in my mongoDB collection using TTL feature of it, and it works as expected, but not fully. It deletes the document later than the specified time.

I specified delete time 10seconds, but sometimes it takes 20seconds to delete it, sometimes 50seconds. Maybe I am making some mistake. I have used UTC date format, and tried with my local area date format too, but still the same. How do I resolve this problem?

One more thing that I want to ask, lets say somehow it works, and I have thousands of documents in my collection, will it decrease the performance of my database for requests and response handling??

because I am not deleting the whole collection, but individual documents, so keeping track of them might decrease performance, am I right?

Here is what I tried.

this is my schema

const mongoose = require('mongoose');

const tokens = mongoose.Schema({

   token: String,

   createdAt:{
      type: Date,      
      expires: 10,
   }
   
});
module.exports = {
   authTokens: mongoose.model('Authtoken', tokens)
}

THIS HOW I AM CREATING DOCUMENT IN COLLECTION

app.post('/createToken', async (req, res) => {
   try{      
      //create document in authTokens Collection
      await authTokens.create({
         token: req.body.token,   
         createdAt: new Date().toUTCString() //getting utc value of date
      });
   }

   catch (err) {
      res.send("Could not send token!");
      console.error(err);
      return;
   }   
   res.send("Document Created Successfully");
   return;
});

Can anyone help please

Thanks



Solution 1:[1]

I assume, that you are using the aws-java-sdk s3client. Therefore you just need to set the endpoint-configuration (for example http://localhost:9000, if minio runs on port 9000 on your local machine)

For more infos about the endpoint-configuration, you can look here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Marcel Herhold