Created
February 2, 2018 16:34
-
-
Save Igor-Lopes/fbb3d866a9331bba1e561936757ab18b to your computer and use it in GitHub Desktop.
Add timestamps and expiration to mongoose schema
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var schema = mongoose.Schema({ | |
email: { | |
type: String, | |
required: true, | |
lowercase: true, | |
index: { | |
unique: true | |
} | |
}, | |
expireAt: { | |
type: Date, | |
/* Defaults 7 days from now */ | |
default: new Date(new Date().valueOf() + 604800000), | |
/* Remove doc 60 seconds after specified date */ | |
expires: 60 | |
} | |
/* Automatically add createdAt and updatedAt fields to schema */ | |
}, { timestamps: true }) |
I tried to detail the "expires" option in the following gist: https://gist.github.com/boly38/2d3ead05b2491924ec97ac4d18a86528
i would like to set the expiration time when the schema get created no a default one !!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could you please tell me what did you mean by "specified date" more specifically?