getting distinct values from result set in taffyDB

97 views Asked by At

I have a TAFFYDB database that consists of 4 fields: clientID cTech arDate active

What I want is a unique list of "cTech" for a certain clientID inside of a range of dates.

I can match clientID and dates like this:

  var ret=clientTechsDB([{
    "clientID":cFrom.toLowerCase(),
    "arDate":{gte:sDfrom},
    "arDate":{lte:sDto},
  }]).get(); 

That returns the array "ret", but ret has many duplicated cTech values.

I tried

  var ret=clientTechsDB([{
    "clientID":cFrom.toLowerCase(),
    "arDate":{gte:sDfrom},
    "arDate":{lte:sDto},
  }]).get().distinct("cTech");    

but that generates and error "get(...).distinct is not a function"

I can iterate through and filter out duplicates but I was hoping to do it in a taffyDB query. How?

1

There are 1 answers

0
Shawn On BEST ANSWER

You don't need "get" when using distinct. The correct syntax is:

var ret=clientTechsDB([{
    "clientID":cFrom.toLowerCase(),
    "arDate":{gte:sDfrom},
    "arDate":{lte:sDto},
  }]).distinct("cTech");