Skip to content

Instantly share code, notes, and snippets.

@Igor-Lopes
Created February 2, 2018 16:34
Show Gist options
  • Save Igor-Lopes/fbb3d866a9331bba1e561936757ab18b to your computer and use it in GitHub Desktop.
Save Igor-Lopes/fbb3d866a9331bba1e561936757ab18b to your computer and use it in GitHub Desktop.
Add timestamps and expiration to mongoose schema
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 })
@DjibrilM
Copy link

DjibrilM commented Sep 5, 2022

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