wixData.query - .ne() Return Value Issues

I am trying to run a query, which only gives back items that have a field value which is not included in an array. The query that I get back, always includes items with values that are in my array and should therefore be excluded.

If I understand the documentation correctly, this should be possible:
If the value of the propertyName property is an Array, ne() includes items in which none of the elements of the Array match the specified value.

My code:

function display_next_user() {
     wixData.query("Users")
        .ne('row_num', user_clicked) //user_clicked is the array
        .find()
        .then( (results) => {
            let items = results.items[0]
            let firstname1 = items.vorname;
            let lastname1 = items.nachname;
            let user_rownum = items.row_num;
            $w("#text3").text = firstname1;
            $w("#text4").text = lastname1;
            user_clicked.push(user_rownum);
        } );
}

The query that I get with this code includes the first item, although it should be excluded.

 {"items":[{"_id":"46c869f8-b80a-464c-83be-5a34c75d9cae","vorname":"Max","punkte":5,"row_num":0,"_createdDate":"2018-05-21T13:24:36.125Z","_updatedDate":"2018-05-21T17:33:40.249Z","_owner":null,"schule":"School","jahrgang":"11","nachname":"M."} 

In the Developer Console, I get the following line at the end of the query result.

"length":13,"totalCount":13,"query":{"invalidArguments":[],"filterTree":{"$and":[{"row_num":{"$ne":[0]}}]},"provider":{},"collectionName":"Users","limitNumber":50,"included":[]}} 

What am I doing wrong?

Thanks

1 Like

Hi there,
The docs say that the actual value in the collection may be an array, not the parameter you pass to ne(). The difference:

  • your expected behavior: only items where the value of the field matches none of the items of the supplied array are returned
  • actual behavior: only items where the value of the field (which is an array) does not contain the supplied value are returned

Try this instead:

query.not(wixData.query(collectionId).hasSome('row_num', exclusions))

Hi, thanks a lot!!