Last active
September 20, 2019 03:52
-
-
Save aofleejay/c51fbd0ff4266183c3e26aca8150cc04 to your computer and use it in GitHub Desktop.
Set mongodb document expiration from mongoose.
This file contains hidden or 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
const mongoose = require('mongoose') | |
mongoose.connect('mongodb://localhost:27017/playground', { | |
useNewUrlParser: true, | |
}) | |
const catSchema = mongoose.Schema( | |
{ | |
name: String, | |
age: Number, | |
}, | |
{ timestamps: true }, | |
) | |
catSchema.index({ createdAt: 1 }, { expireAfterSeconds: 15 }) | |
const Cat = mongoose.model('Cat', catSchema) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment