Hello @Massimiliano_Ricci1 .
Welcome to Mongodb community.

I suspect the issue you are having could be due to below reson.
Default createdAt value : In your Mongoose schema definition, you’re setting the default value for createdAt to new Date() , which means it will be set to the time when the schema is compiled, not the time when the document is created.

This could be the reason why the TTL index doesn’t work as expected. Try setting the default value using a function instead:

createdAt: {
    type: Date,
    default: Date.now
}