I'm planning to $convert my field to date because it is currently a string.
My Collection
"name": "Roboert Browning",
"delivery": [{
"status": "Not Started",
"createdAt": "$date": "2020-12-21T03:50:33.877Z",
"updatedAt": "$date": "2020-12-21T03:50:33.877Z"
}, {
"status": "Accepted",
"updatedAt": "$date": "2020-12-21T03:51:20.915Z",
"createdAt": "$date": "2020-12-21T03:51:20.915Z"
}],
"price": 500,
"targetDate": "2020-12-08T11:50:15.659562",
"createdAt": 2020-12-08T11:36:48.285+00:00,
"updatedAt": 2020-12-09T12:02:06.426+00:00
I would like to match the createdAt to the targetDate if they are the same date, but it is currently a string. I want to convert the targetDate to Date so I can match them.
Current implementation
{
$match: {
"$expr": {
"$eq": [
{ "$dateToString": { "format": "%Y-%m-%d", "date": "$createdAt" } },
{ "$dateToString": { "format": "%Y-%m-%d", "date": "$targetDate" } }
]
}
}
}
I'm getting an error can't convert from BSON type string to Date
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…