Using mongoose, you can successfully add an expiration time to a document:
However, the data is still not deleted after the set expiration time. The official document says that the mongo background service polls the expiration setting every one minute, but this is no longer a matter of a few minutes delay. It feels like expire has not taken effect. of
I solved this problem myself and re-read the official documentation https://docs.mongodb.com/manu...
The index defined by schema must correspond to the actual data.
The createAt in schema must correspond to the createAt in arr, and the time must be given for it to take effect.
let mySchema = new mongoose.Schema(...)
Try it?Some suggestions:
1. First check the actual TTL situation of the index; in the part you posted, I feel that the code above is inconsistent with the screenshot below
2. Look at the ttl part in server.Status
db.serverStatus().metrics.ttl
For reference.
Love MongoDB! Have fun!