尝试使用 sequelize 查询 postgres JSON 数据类型

cec*_*ode 5 postgresql node.js sequelize.js

我的表中有一个新创建的列,我需要在我的服务器控制器之一中进行查询。此列中的此数据将为 JSON 类型,并命名为“meta”。完成后看起来像这样

{
  "audit": {"date": 1465311598315, "user": 20191932891}
}
Run Code Online (Sandbox Code Playgroud)

目前,该表中的所有条目都有一个空的 JSON 列和一个 NULL 值。

在我的一个服务器控制器中,我需要获取所有元数据为 null 或 meta.audit.date 超过 90 天的条目。我的查询看起来像这样

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

在这种情况下,三个月前是三个月前的日期作为数字。

没有返回任何结果,我在控制台中收到此错误:

Unhandled rejection SequelizeDatabaseError: operator does not exist: text <= bigint
Run Code Online (Sandbox Code Playgroud)

cec*_*ode 5

原来我没有正确使用 $or 运算符

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

  }
});
Run Code Online (Sandbox Code Playgroud)