Search code examples
node.jsstrongloop

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) {
  });

Solution

  • Try this

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