Categories
JavaScript Answers

How to add a timestamp field with Mongoose and JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *