6

I have a newly created column in my table I need to query in one of my server controllers. This data in this column will be of JSON type and is named "meta". It will look something like this when completed

{
  "audit": {"date": 1465311598315, "user": 20191932891}
}

currently all of the entries in this table have the empty JSON column with a NULL value.

In one of my server controllers I need to grab all entries where where meta is null or meta.audit.date is more than 90 days old. My query looks something like this

  db.Question.findAll({
  where: {
    status: 'active',
    PassageId: {
      $eq: null
    },
    meta: {
      audit: {
        date: {
          $or: {
            $lte: threeMonthsAgo,
            $eq: null
          }
        }
      }
    }
  }
});

In this case three months ago is the date three months ago as a number.

No results are being returned and I get this error in my console:

Unhandled rejection SequelizeDatabaseError: operator does not exist: text <= bigint

1 Answer 1

6

Turns out I wasn't using the $or operator correctly

db.Question.findAll({
  where: {
    status: 'active',
    PassageId: {
      $eq: null
    },
    {
      $or: [{
        'meta.audit.date': {
          $eq: null
        }
      }, {
        'meta.audit.date': {
          $lte: threeMonthsAgo
        }
      }]
    }

  }
});
1
  • 1
    Since date type is stored as string in JSON, here 'meta.audit.date' is a string. Do you need to convert it to date before comparing with threeMonthsAgo which is a date I assume?
    – user938363
    Commented Jul 15, 2019 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.