We were looking at creating a calculated field in one of our charts, and this should be derived from the existence of a field. We’ve tried several versions of this that don’t seem to yield the correct value.
We tried
{
$cond: {
if: {
$eq: ["$artistProfileId", null]
},
then: "Organiser",
else: "Artist"
}
}
The above always yields the same value (“Artist”) which is incorrect.
Testing for null
doesn’t feel like the right option anyway, because in some documents the field is actually missing. However, a version with $exists doesn’t compile (InvalidPipelineOperator):
{
$cond: {
if: {
"$artistProfileId": {$exists: true}
},
then: "Artist",
else: "Organiser"
}
}
Any ideas how we can derive this calculated Chart field based on the existence of a field?