How so I check if the unwind field is null?
[
{
$lookup: {
....,
as: "user"
},
{
$unwind: {
path: "$user",
preserveNullAndEmptyArrays: true
}
},
{
$project: {
isValid: {
$cond: [{$eq: ["$user", null], '123', 'abc']
}
}
}
]
The example above is just to print 123 is the unwinded $user is null / undefined / does not exist, and ‘abc’ is if it exists. (it’s an example, as the MongoDB always returns ‘123’).
I have also tried $cond: [ {'user': {exitst: true}}, true, false]
and it didn’t work, always returned true alsoe