Mongo Db Time format [closed] Mongo Db Time format [closed] mongodb mongodb

Mongo Db Time format [closed]


you can user mongoose user schema's pre function which trigger every time you added anything using the schema. inside that use conditional function how you want to save the specific schema model . i have done your time model . let me know if you have any confusion.

var mongoose = require('mongoose'),Schema = mongoose.Schema;var UserSchema = new Schema({time: String});UserSchema.pre('save',function (next) {    if (!this.time) {        var newdate = new Date();        var Fulllocaltime =  newdate.toLocaleString('en-US');        var array = Fulllocaltime.split(" ");        var finaloutput = array[1]+' '+array[2];        this.time =finaloutput;    }    next();});