Mongoose Model:
const patientSchema = new mongoose.Schema({
firstName: String,
middleName: String,
lastName: String,
addresses: [addressSubschema],
dateOfBirth: Date,
files: [{ type: mongoose.Schema.Types.ObjectId, ref: 'File' }],
policies: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Policy' }],
claims: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Claim' }],
authorizations: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Authorization' }],
statements: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Statement' }],
documents: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Document' }],
notes: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Note' }]
}, { timestamps: true })
I'm using a React front end and a standard Node.js/Express back end. After I create a new patient, the date of birth gets stored as a string in the document like this:
1990-05-05T00:00:00.000+00:00
When I query for this file and attempt to display the date, I'm originally allowed to display the date exactly as it comes over:
<p className="card-text">{props.data.dateOfBirth}</p>
React normally won't let you print an object directly to the screen, so right off the bat I know this is a string and not a date object
That original format is not user friendly of course, so I attempted to convert the string to a date by runnin it through new Date()
, but when I did so, this is the response I got:
I'm getting converted to my timezone and the date will end up displaying wrong. In the past, I always remember Mongoose returning me a date object that I needed to convert to a string.
My main question is: How can I get Mongoose to give me date only objects? I don't want to have to worry about times with this particular date. I just need the date.