moment js not updating in mongoose moment js not updating in mongoose mongoose mongoose

moment js not updating in mongoose


This line of code will only be executed once, when the module is loaded:

var now = moment();

So the same value of now will be used for all documents.

Instead, your schema definition should use a function which will be called each time a new document is created:

var UserSchema = new mongoose.Schema({    email: { type: String, default: ''},    name: { type: String, default: ''},    password: { type: String, default: ''},    timestamp: {        type: String,         default: () => moment().format("dddd, MMMM Do YYYY, h:mm:ss a")    }});

As a side note, consider using a Date data type instead of string for your timestamp as it's more flexible and efficient.