group in mongo excluding null values

前端 未结 3 2050
-上瘾入骨i
-上瘾入骨i 2021-01-17 10:58

I have mongo query which does the group operation on the documents.

I have almost got the expected results except that I want to refine the results without empty or

3条回答
  •  不知归路
    2021-01-17 11:40

    Perhaps you should use $match: {'color': {$exists: true}} before $group operation. With sparse index it will work pretty fast. And do not store "null" fields in collections at all, that will reduce db size and will increase search speed for sparse indexes (less documents in index -> more speed)

提交回复
热议问题