Reputation: 261
MongoDB provide "Date" datatype using this we can save complete datetime. What is the best way to do that. Want to do like that because need to store multiple 'Dates' for specific 'From Time' and 'To Time'
Assign date and time as 'Date' datatype but got this error after that "Space validation failed: timeFrom: Cast to Date failed for value \"12:52\" at path \"timeFrom\", timeTo: Cast to Date failed for value \"01:52\" at path \"timeTo\""
let selectedDates = [
"2019-09-16",
"2019-09-17",
"2019-09-20"
]
let dateFrom = moment('2019-09-16T12:52').format('hh:mm')
let dateTo = moment('2019-09-16T12:52').format('hh:mm')
let collection = new someCollection({
selectedDates: param.selectedDates,
timeFrom: dateFrom,
timeTo: dateTo,
})
collection.save();
Expected output:
{
"selectedDates": [
"2019-09-16",
"2019-09-17",
"2019-09-20"
],
"timeFrom": 05:10,
"timeTo": 05:50
}
Upvotes: 4
Views: 346
Reputation: 261
After reading lot of blogs got only solution is that to use "String" datatype for mongoDB schema. If we use "Date" as datatype then we can't get desired result.
Upvotes: 6