Ramon Luis Ramon Luis - 19 days ago 7
Node.js Question

Strongloop querying data with (or) and (and) at the same time

I need to do this.

select *
from person
where (firstname like '%a' or lastname like "%a") and id NOT IN (1 , 2)


node.js:

BegroupdUser.find({
limit: limit,
skip: skip,
where: {
id: { nin: adminIds },
or: [{
firstName: {like: '%' + _query + '%'}
}, {
lastName: {like: '%' + _query + '%'}
}]
}
}, function (errors, users) {
});

Answer

Try this

{
  "where": {
    "and": [
      {
        "id": {
          "nin":  adminIds
        }
      },
      {
        "or": [{
                firstName: {like: '%' + _query + '%'}}, 
                {
                lastName: {like: '%' + _query + '%'}}
              ]
      }
    ]
  }
}