StefanM
StefanM

Reputation: 63

Removing the expiry time of document in Mongoose

So I am expanding my MEAN application to only save new registrations to the website only if they have correctly pressed a unique link from a sent email.

The link will essentially form a route with the documents _id as the param so that mongoose knows which user to save.

I have a relatively basic user schema:

{
    username: {
        type: String,
        lowercase: true,
        unique: true
    },
    firstname: String,
    lastname: String,
    createdAt: {type: Date, expires: 3600, default: Date.now},
    hash: String,
    salt: String
};

Now what I would like to do is to remove the expiry time or the TTL index on a document, however I only seem to be able to delay the timer by changing the createdAt date.

Is there any smart way of doing this? Otherwise I could just have Mongoose save the document from a temporary collection to a persistent one?

Upvotes: 1

Views: 698

Answers (1)

StefanM
StefanM

Reputation: 63

I ended up just creating a new Scheme without the expires key and simply copying the data from one collection to the other when I wanted the expiry time to stop.

Not the cleanest solution, but it does get the job done, and this way you have a full collection of data without an expiry timer.

Upvotes: 1

Related Questions