'MongoDB - Aggregation - Projection. I want to conditionally check if value of a other field exists or not. Based on that I want true or false

        {
            $project: {
                todayTimings: {
                    isOpen: "$doctorSettings.todayTimings.isOpen",
                    timeSlots: "$doctorSettings.todayTimings.timeSlots",
                    isSpecial: {
                        $cond: {
                            if: {
                                "$doctorSettings.todayTimings.date": {
                                    /* $exists: true,
                                    $notNull: true */
                                    // I want to check if date is there and has value or not.
                                }
                            },
                            then: true,
                            else: false,
                        },
                    },
                },
            },
        },

What is the best way to do this?

I tried $exists within $cond..if but it didn't work. It found $exists as unknown. There isn't much of doc on google for this. I want a better guide for this.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source