I am facing this error while using $dateFromString
MongoServerError: PlanExecutor error during aggregation :: caused by :: $dateFromString requires that 'dateString' be a string, found: date with value 2022-09-08T12:45:30.811Z
In my schema, I did { timestamps: true } to save createdAt and updatedAt.
db.collection.aggregate([{
$group: {
_id: {
createdAt: {
$dateFromString: {
dateString: '$createdAt'
}
}
}
}
}])
The object in mongodb is saved as:
{
_id: new ObjectId("6319e3ea8fec56ded0173275"),
isAvailable: true,
createdAt: 2022-09-08T12:45:30.811Z,
updatedAt: 2022-09-08T12:45:30.811Z,
__v: 0
}