db.getCollection('catalog').aggregate([{$match: {"category" : 4}},{$group : {"_id" : "$licence_Type_Code"}}]) ```
注意:
1、 "_id"是固定写法,值是依据的分类字段名(字段名记得加“$”符号)
2、$match和$group前后顺序可以灵活变化,不一定是谁在前谁在后
var qu = db.getCollection('catalog').aggregate([{$match: {"category" : 4}},{$group : {"_id" : "$licence_Type_Code"}}]);
var arr = [];
var i = 0;
while(qu.hasNext()){
arr[i] = qu.next()._id;
i++;}
print(arr);