Cannot seem to get a $cond working inside a $sum function...

102 views
Skip to first unread message

Alex Paransky

unread,
Jul 1, 2015, 6:03:48 PM7/1/15
to mongod...@googlegroups.com
I want to conditionally sum some values.

The following works:

db.events.aggregate([

     {

              $match : filters

     },

     {

              $group : {

                     _id : dimensions,

                      'playSuccessCount' : {

                         $sum : {

                                $cond : {if : true, then : 1, else : 0}

                         }

                      },

                     'pageLoadCount' : {$sum: 1}

            }

      }

]);


But this query does not work (seems to be related to the $eq) conditional {$eq : ['$vd.T' : 'qos'] } :

db.events.aggregate([

     {

              $match : filters

     },

     {

              $group : {

                     _id : dimensions,

                      'playSuccessCount' : {

                         $sum : {

                                $cond : {if : {$eq : ['$vd.T' : 'qos'] }, then : 1, else : 0}

                         }

                      },

                     'pageLoadCount' : {$sum: 1}

            }

      }

]);


All I am trying todo is to conditionally sum up the plageSuccessCount, but I seem to be getting a syntax error.  Is $eq not supported in this context?


Thanks.

-AP_




Alex Paransky

unread,
Jul 1, 2015, 6:06:25 PM7/1/15
to mongod...@googlegroups.com
My bad, {$eq : ['$vd.T' : 'qos'] }, should have been {$eq : ['$vd.T' , 'qos'] }
Reply all
Reply to author
Forward
0 new messages