E
E
EpicUsaMan2017-08-03 15:45:23
JavaScript
EpicUsaMan, 2017-08-03 15:45:23

How to fix $cond?

{
                $group: {
                    '_id': '$ft',
                    'orig_id': {
                        $last: '$_id'
                    },
                    'from': {
                        $last: '$from'
                    },
                    'to': {
                        $last: '$to'
                    },
                    'msg': {
                        $last: '$msg'
                    },
                    'date': {
                        $last: '$date'
                    },
                    'unreaded': {
                        $sum: {
                            $cond: [{
                                $ne: ['$read', 142]
                            }, 1, 0]
                        }
                    }
                }
            }

There is such a grouping condition, for example, only one element is grouped:
{ "_id" : ObjectId("598308c3036f7311e3ddcfec"), "from" : 202, "to" : 142, "msg" : "123", "date" : ISODate("2017-08-03T11:28:03.462Z"), "read" : [ 202, 142 ], "favor" : [ ] }

The unreaded field is 1 when the read field is [202], unreaded is also 1.
What is the reason?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
emp1re, 2017-08-03
@EpicUsaMan

Array operators $in and $nin, $ne analog !=
example

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question