To add a timestamp field with Mongoose and JavaScript, we set the timestamps option to true.
For instance, we write
const mySchema = new mongoose.Schema({ name: String }, { timestamps: true });
to create a schema with the name string field.
We set timestamps to true to make it a timestamp field.