Updating "expires" with mongoose
mongodb, mongoose, node.js
Solution
The only way to do that is to set the value to `null`. You'd lose your `createdAt` value, which you might not want so what I'd personally do is this:
- Remove the `expires` index on the existing field.
- Create a field named `expires` or `deletionDate` with the 4 hour time to live.
- If the user should not be deleted, set the value to `null`.
I personally prefer to set the `ttl` to 0 and set the date to `{default: function() { return new Date(Date.now()+1000*60*number_of_hours); }`. That would make it easier to arbitrarily extend the time to live of a document and it's easier to read in the db.
Problem
I am new to mongodb and mongoose, and I am having a hard time figuring out how to do the following. I have a Schema, say "User", which includes a field like this: ``` createdAt : {type: Date, required: true, default: Date.now, expires: '4h'} ``` Therefore, when I create a new user, say `var user=new User()` (assume User `requires` the correct model), the new user created will be deleted after (approximately) 4h (if I understood it correctly). I was wondering if there is a way to update the `expires` property of a user. I would like to do the following: - Retrieve the user from my database - Update `expires`, such that the user does NOT expire anymore - Save the changes Any suggestions will be highly appreciated!