I have data stored in a Postgres 11 table, one of the columns has a json object as it follows:
id | data | client_id |
---|---|---|
1 | JSON | BR_123 |
{
"shed": false,
"transactions": [
{
"id": 1,
"value": 5000,
"depositDate": "2021-09-20T10:29:05.000Z",
"expirationDate": "2022-03-29T10:29:05.000Z",
"requestDate": "2021-09-17T17:04:43.000Z"
}
],
"applies": false,
"importValue": null,
"depositValue": null
}
What I'm trying to do is select all of the entries that have a 'transactions.value' greater or equal than a given amount.
Sequelize:
const clients = await ComercialImports.findAll({
where: {
status: 'Running'
},
attributes: ['id', 'mode', 'importerId'],
include: [
{
model: ComercialImportsTransactions,
as: 'importTransaction',
attributes: ['id', 'data', 'clientId'],
required: true,
where: {
data: {
transactions: {
value: {
[Op.gte]: 5000
}
}
}
}
}
]
});
Unfortunately, for some reason this query won't work, as it always return 0 results. I can't seem to access any values stored on the transactions entry. All other entries are accessible (e.g. I can query for all data with 'shed' = true)
What am I doing wrong?