2016-06-07 56 views
3

我在我的表中有一个新创建的列,我需要在我的一个服务器控制器中查询。该列中的这些数据将是JSON类型,并被命名为“meta”。它看起来像这样完成后试图查询PostgreSQL的JSON数据类型与集合

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

当前该表中的所有条目都具有空值的JSON列。

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

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

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

没有结果返回和我在控制台收到此错误:

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

回答

2

原来我不使用$或操作正确

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

    } 
});