MongoDB aggregate by field exists

前端 未结 6 1452
不思量自难忘°
不思量自难忘° 2020-12-02 12:33

I have a hard time believing this question hasn\'t been asked and answered somewhere already, but I can\'t find any trace of it.

I have a MongoDB aggregation query t

6条回答
  •  佛祖请我去吃肉
    2020-12-02 12:59

    My answer is:

    {$match:{
        $and:[{
            name:{
                $exists:true
            }
        }, {
            $expr:{
                $eq:["$$id", "$_id"]
            }
        }]
    }}
    

    I use this in lookup, on my pipeline stage. This post 2 rules the first one, name must exist. And the second thing is the relation between these 2 collection. I Am sure u can modify this for your question.

提交回复
热议问题