0

I have some conditions and a level to check while fetching records from collection using MongoDB.

For this I am using below

def cursorOutput = dataSetCollection.find(whereObject,criteriaObject)

Which is working fine. but I want to use distinct with combination to above query.

def distinctMIdList = dataSetCollection.distinct(hierarchyField,whereObject)

Above is the query for distinct. How to combine two query.

I tried below which is not working

def cursorOutput = dataSetCollection.find(whereObject,criteriaObject).distinct("manager id")

whereObject is a condition to fetch results and criteriaObject is fields to fetch.

Distinct query is giving me result with only Manager id field but I am looking for other field also(use of criteriaObject).

Finally how to combine above two query. I searched for pipeline where $distinct is not available.

Thank you.

1 Answers1

0

Map function:

   var mapFunction = function() {
       if(/*your criteria*/) {
           emit("manager_id", this.manager_id);
       }
    };

Reduce Function:

   var reduceFunction = function(managerFiled,values){
       return Array.unique(values);
   }
SalaryNotFound
  • 224
  • 1
  • 8