的數量可以說我有記錄的集合: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'}]
使用具有「組」的聚合流水線 –