的数量可以说我有记录的集合:MongoDB中获得不同的值
{'name':'record1', 'colors':['red','green','blue']}
{'name':'record2', 'colors':['red','orange']}
{'name':'record3', 'colors':['red','yellow','blue']}
{'name':'record4', 'colors':['red','green','blue']}
我可以用得到的不同颜色的列表:
collection.distinct('colors')
#returns
['red','green','blue','orange','yellow']
是有可能得到的计数这些值发生的记录?
例如:
[{'count':4,'color':'red'},{'count':2,'color':'green'}]
使用具有“组”的聚合流水线 –