For background, if I want to compare two fields, I can\'t use the following syntax (because it compares to the literal string \"$lastName\" rather than the contents of the $last
You will need to use the $or logical operator to do this.
$or
{ "$or": [ { "$expr": { "$ne": [ "$firstName", "$lastName" ] } }, { "fullName": { "$exists": true } } ] }
You last query failed because mongod thinks $exists is the expression you are passing the the $expr operator.
$exists
$expr