I am trying to use moment(new Date().toISOString() in mongoose model as shown below
var mongoose = require('mongoose');
var uniqueValidator = require('mongoose-unique-validator');
Schema = mongoose.Schema;
var moment = require('moment');
// https://www.npmjs.com/package/mongoose-unique-validator
var categorySchema = new mongoose.Schema(
{
CatId:{ type: Number, required: true, unique: true },
Name : { type: String, required: true, unique: true },
Description : String,
Is_Active:Number,
Db_Created_TimeStamp:{type:Date,default: moment(new Date().toISOString())},
Db_Updated_TimeStamp:{type:Date,default:moment(new Date().toISOString())},
},{collection: "Categories"})
categorySchema.plugin(uniqueValidator);
mongoose.model('Categories',categorySchema);
when data is inserted in the mongodb always it is showing the same time
Not sure whether i am missing some thing
The idea of doing it is getting the time stamp including millisecond
{
"_id" : ObjectId("5a163a14ed910b1279d7ca3f"),
"Is_Active" : NumberInt(1),
"Description" : "spo22rt",
"Name" : "spo22rt",
"CatId" : NumberInt(2),
"Db_Updated_TimeStamp" : ***ISODate("2017-11-23T03:01:25.349+0000"),
"Db_Created_TimeStamp" : ISODate("2017-11-23T03:01:25.346+0000"),***
"__v" : NumberInt(0)
}
{
"_id" : ObjectId("5a163a2ced910b1279d7ca40"),
"Is_Active" : NumberInt(1),
"Description" : "spossss22rt",
"Name" : "spo22rsst",
"CatId" : NumberInt(1),
"Db_Updated_TimeStamp" : **ISODate("2017-11-23T03:01:25.349+0000"),
"Db_Created_TimeStamp" : ISODate("2017-11-23T03:01:25.346+0000"),
"__v" : NumberInt(0)**
}
Here the first record i have inserted is having time 2017-11-23T03:01:25.349+0000
After 3 minutes i inserted the second record but still same time in db
2017-11-23T03:01:25.349+0000
I am trying this insertion at 8:40AM but i am not sure what is that time 03:01:25
I am missing something fundamentals i think almost spent a day to understand but no clue to understand what is happening please help me in understanding this