Dynamic Or query is empty , gives error - "$and/$or/$nor must be a nonempty array"

Viewed 562

I want the query to have the or condition where if it is empty, it should return an empty result. But since or query is empty, it returns an error '$and/$or/$nor must be a nonempty array'.

How can I bypass this, noting if the or query is empty I need the result to be empty.

matchOrs is an array, which is the $or query and is usually non empty but sometimes results in an empty array as well which results in the issue- '$and/$or/$nor must be a nonempty array'

const match = {
    '$and': [{
      'status': {
        '$ne': 'rejected',
      },
    },
    {
      'raised_date': {
        '$gt': start,
        '$lte': end,
      },
    },
    {
      '$or': matchOrs,
    },
    {
      'city': city,
    }],
  };
0 Answers
Related