如何在mongodb中使用distinct with aggregate方法
在使用MongoDB从集合中获取记录时,我需要检查一些条件和级别 为此,我在下面使用如何在mongodb中使用distinct with aggregate方法,mongodb,grails,distinct,Mongodb,Grails,Distinct,在使用MongoDB从集合中获取记录时,我需要检查一些条件和级别 为此,我在下面使用 def cursorOutput = dataSetCollection.find(whereObject,criteriaObject) 这很好用。但我想使用distinct with组合来进行上述查询 def distinctMIdList = dataSetCollection.distinct(hierarchyField,whereObject) 上面是对distinct的查询。如何组合两个查询
def cursorOutput = dataSetCollection.find(whereObject,criteriaObject)
这很好用。但我想使用distinct with组合来进行上述查询
def distinctMIdList = dataSetCollection.distinct(hierarchyField,whereObject)
上面是对distinct的查询。如何组合两个查询
我在下面试过了,但不起作用
def cursorOutput = dataSetCollection.find(whereObject,criteriaObject).distinct("manager id")
其中object是获取结果的条件,criteriaObject是获取结果的字段
Distinct查询给我的结果只有一个Manager id字段,但我也在寻找其他字段(使用criteriaObject)
最后介绍了如何结合以上两种查询。我搜索了$distinct不可用的管道
谢谢。地图功能:
var mapFunction = function() {
if(/*your criteria*/) {
emit("manager_id", this.manager_id);
}
};
减少功能:
var reduceFunction = function(managerFiled,values){
return Array.unique(values);
}
复制