Hello, I wonder if there is a directive to set `ex...
# orm-help
s
Hello, I wonder if there is a directive to set
expireAfterSeconds
for MongoDb? I'd like to set an expiration time for value. Thank you.
h
Hi, I think this is something you should implement in you custom server. Can you also brief me about what you mean by expire(either deletion or something else)?
s
Hi, it's when the value gets deleted after time expires. Useful for storing tokens for restoring passwords etc. Usually, they are valid for limited time and it is convenient that DB removes them rather than you have to take care of it
h
I think you should implement a shared queue for this. I don't this is something that we can implement on the datalayer. You can use bull here: https://www.npmjs.com/package/bull
s
MongoDb supports TTL so using it would be an ideal solution
While your suggestion would work, doing it natively is way more elegant
Would it make sense to make a feature request?
@Harshit
h
Oh ok, if it is just an index this will be possible in datamodel v1.1: https://github.com/prisma/prisma/issues/3405
Please make a comment about this there and tag
@mavilein
in it
BTW datamodel v1.1 is currently in beta under a prototype flag
s
and it supports TTL?
in Mongoose what I need looks that simple
Copy code
// expire docs 3600 seconds after createdAt
new Schema({ createdAt: { type: Date, expires: 3600 }});
h
This is simply an index so I think it would be possible to create one using @index directive