I am creating an aggregate query, but I'm running into an issue with some of my fields that need to be converted to ObjectIDs'. There are certain documents that do not have anything in the fields(null, ''), so I want to ignore those cases.
{
"$project": {
"Company": {
"$toObjectId": "$Company"
},
"Lease": {
"$toObjectId": "$Lease"
},
"Well": {
"$toObjectId": "$Well"
}
}
I've tried something similar to this:
{$ifNull: [{ $toObjectId: "$Company" }, ''] }
But I'm still receiving the error.
What is the best way to fix this?