Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

368
Visualizações
Sequelize query with nested array object json

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?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda