jquerytaffydb

taffyDB query for "not in" set


Using TaffyDB(), I want to query out data while excluding values from a list.

I'm trying like this:

var ret=clientDB( {"xuserID":{ "!is":["STS","EIAI"] } } ).get();

Using that, it correctly omits the 1st value (in this case STS) but not any proceeding values.


Solution

  • I am not aware of a way to do this.

    While not technically the answer to your question, one possible alternative would be to return anything that is not "STS" AND not "EIAI".

    var ret=clientDB
    (
        {xuserID:{"!is":"STS"}},
        {xuserID:{"!is":"EIAI"}}
    ).get();
    

    It might be worth noting, depending on how you need the data represented, that TAFFYDB's get() method returns the found records as an array, so you could just search for the records you know you don't want and then filter the two arrays against one another like this.

    var entire_as_array = clientDB().get();
    var unwanted_portion_as_array = clientDB({xuserID:["STS","EIAI"]}).get();
    var concat_array = entire_as_array.concat(unwanted_portion_as_array);
    
    var difference = concat_array.filter(function(i){
          return entire_as_array.indexOf(i) < 0 || unwanted_portion_as_array.indexOf(i) < 0;
        });