I have previously asked a question about converting string to dates - Convert Date to String in nested array in mongodb - and got a great and working answer. The only issue is that when a date is a blank -> '' then I get the following error:
{
"message" : "an incomplete date/time string has been found, with elements missing: ' '",
"ok" : 0,
"code" : 241,
"codeName" : "ConversionFailure",
"name" : "MongoError"
}
the formula Im using (taken from question) is:
db.cases.aggregate([
{ $match: { companyID: 218 }},
{ "$addFields": {
"cases": {
"$map": {
"input": "$cases",
"in": {
"$mergeObjects": [
"$$this",
{
"createddate": {
"$dateFromString": { "dateString": "$$this.createddate" }
},
"endDate": {
"$dateFromString": { "dateString": "$$this.endDate" }
}
}
]
}
}
}
}}
])
I have tried adding in
{ $unwind: "$cases" },
{ $match: { 'cases.endDate': {'$ne' : ''}}},
But that gave me an error saying:
{
"message" : "input to $map must be an array not object",
"ok" : 0,
"code" : 16883,
"codeName" : "Location16883",
"name" : "MongoError"
}
Any help would be appreciated.
Thank you