Reputation: 135
I am having trouble converting "7/26/2020 18:34:25" into any date format from which Mongo can run aggregate operation.
The date in the Mongo is stored as string. I have tried "$toDate", "$convert" and "$dateToString".
Upvotes: 0
Views: 97
Reputation: 21
Try using Moment Library for converting you date In your case this code can help you:
moment('7/26/2020 18:34:25').toDate();
You can test this code on browser side on this page enter link description here
Upvotes: 0
Reputation: 22974
You need to use $dateFromString
$project: {
date: {
$dateFromString: {
dateString: '$dateFieldName',
format: '%m/%d/%Y %H:%M:%S'
}
}
}
Upvotes: 2