I have a Mongoose Schema where I am assigning a default value to a field by calling a function.
My schema
function fun(){
let curr_time = moment().format();
return curr_time;
};
let flagged_trans_schema = new Schema({
time: {type: Date, default: fun},
});
I am facing a problem here, when I am writing default: fun() then the time field is not getting updated time, but when I am writing default: fun then time field value is updating every time.
Can anyone please tell me why it is happening?