2016-06-07 42 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 
     } 
     }] 
    } 

    } 
});