I am building an application which allows users to create events at a certain time within a 24 hour period and have the event populate on a google map. While I can get the dates to show up and format properly, my new issue is getting them to expire setting a TTL in each document created.
Here is my mongoose schema:
var mongoose = require("mongoose");
var Schema = mongoose.Schema;
var SportSchema = new Schema({
title: {
type: String
},
sport: {
type: String
},
location: {
type: String
},
time: {
type: String
},
lat: {
type: Number
},
lng: {
type: Number
},
expireAt: {
type: Date
}
});
var Sport = mongoose.model("Sport", SportSchema);
module.exports = Sport;`
and the POST route in my server:
app.post("/api/events", function (req, res) {
Helpers.geoLocate(req.body.location)
.then(function (results) {
Sport.create({
title: req.body.title,
sport: req.body.sport,
location: req.body.location,
time: req.body.time,
lat: results.lat,
lng: results.lng,
expireAt: req.body.time
}).then(obj=>res.json(obj));
});
});
Where the expireAt property gets the same time value at the time property. There are examples out there that are passing a certain amount of time until the record deletes. However, I was trying to see if it is at all possible to pass in a BSON date and have it expire when that data/time is met.