Answers for "MongoDB aggregate by field exists"

0

MongoDB aggregate by field exists

$ne:  [ { $type : "$var_to_check"}, 'missing'] }
or
$ne : [$var_to_check, undefined]

# match stage eg:
{
    $match: {
        $expr: {
            $ne: [{
                    $type: "$var_to_check"
                },
                'missing'
            ]
        }
    }
}

# or
{
    $match: {
        $expr: {
            $ne: [$var_to_check, undefined]
            ]
        }
    }
}
Posted by: Guest on September-23-2021

Code answers related to "MongoDB aggregate by field exists"

Browse Popular Code Answers by Language