Would like to know how to run multiple where with Orwhere conditions for queries in version10?

The way I have figured out for now to run where with OrWhere queries is running multiple queries.

lets say I want to find users who are active (status = 1) or who have joined but not active yet(status = 2) (assume there could be multiple possible values for status based on conditions)

let activeusers = users.all().where(.status == 1).toArray() //get active users
let newjoinees = users.all().where(.status == 2).toArray() //get new joinees

let allusers = activeusers.concat(newjoinees); //all active users or new joinees
let distinctusers = allusers.distinct() //get only distinct users if there are duplicates.

So I would like to know how to do the same operation in single query like in SQL.

let allusers = users.all().where(.status == 1).Orwhere(.status == 2).toArray()

Also I could not find anything that can work like whereIn() as in SQL. any examples please.


Sets have a concat method. See our documentation here:

let activeusers = users.all().where(.status == 1) //get active users
let newjoinees = users.all().where(.status == 2) //get new joinees


Will it be useful to you?

let allusers = users.all().where(.status == 1 || .status == 2);

Also, it is possible to search by different fields

let allusers = users.all().where(.status == 1 || .anything == 'something');

One more thing, you can use a more verbose syntax if you’d like

let allusers = users.all().where((user) => user.status == 1 || user.status == 2);
1 Like

@sumerokr’s response is indeed probably better if you are filtering with where.

I was probably thinking too hard about indexes :sweat_smile:. A check for equality like .where(.status == 1) is a good example of something that should be indexed. Use concat if you are combining multiple index reads. You should probably just use logical OR (||) like @sumerokr says for filtering with where

// FSL
collection users {
  history_days 0

  // define an index on the users Collection
  index by_status {
    terms [.status]
// combine multiple index reads
let activeusers = users.by_status(1) //get active users
let newjoinees = users.by_status(2) //get new joinees

// or all in one line