I'm trying to do the following in a mongo pipeline -
{ $project: {
newAttribute: {
$cond: [
{ $exists: { '$myAttribute': true } },
1,
0
]
}
}}
However this throws an error -
Error: command failed: {
"errmsg" : "exception: invalid operator '$exists'",
"code" : 15999,
"ok" : 0
}
I can see someone trying to do something similar here, but $ifNull
doesn't help me because I want the value 1, rather than the value of the myAttribute
field.
Is there a nice way to solve this?