MongoDB - Aggregation - To get unique items in array

前端 未结 4 1375
闹比i
闹比i 2020-12-28 19:44

Here\'s my MongoDB collection:

{
    \"_id\" : ObjectId(\"515d8f53175b8ecb053425c2\"),
    \"category\" : \"Batteries\",
    \"products\" : [
        {
              


        
4条回答
  •  忘掉有多难
    2020-12-28 19:57

    I know it is an old question and you've solved it several years ago! But there is a small problem in the answer you've marked as correct and it may not suitable for all cases. The $unwind is an expensive operator and may affect latency and memory consumption for large datasets. I think the $reduce operator is more performant in this case.

提交回复
热议问题