MongoDB distinct aggregation

前端 未结 4 571
粉色の甜心
粉色の甜心 2020-12-08 06:43

I\'m working on a query to find cities with most zips for each state:

db.zips.distinct(\"state\", db.zips.aggregate([ {$group:{_id:{state:\"$state\", city:\"         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-08 07:31

    You can call $setUnion on a single array, which also filters dupes:

    { $project: {Package: 1, deps: {'$setUnion': '$deps.Package'}}}
    

提交回复
热议问题