2 years ago
#68315
KingJoeffrey
store month/day/year in mongoose schema
I have a mongoose schema with a created key. Currently I am using Date.now which is storing the date value as. 2022-01-12T22:23:49.621Z
Is it possible to store the data as a 01/22/2022 format in the database? Or do I always need to store in this above format and call date functions when I fetch from the db
Here is my model
const mongoose = require ('mongoose')
const { Schema } = mongoose;
const fieldSchema = new Schema ({
title: String,
body: String,
_user: {type: Schema.Types.ObjectId, ref: 'User' },
created: {
type: Date,
default: Date.now // Date.getMonth() + Date.getDay() + Date.getFullYear()
},
})
module.exports = mongoose.model('field', fieldSchema);
mongodb
mongoose
schema
0 Answers
Your Answer