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

294
Visualizações
lowdb - how to query multiple records?

I'm using https://github.com/typicode/lowdb for a small project. I need a query which searches multiple records and returns each record it finds as an array.

For example, for a db such as:

  "records": [
    {
      "id": "sadohfdsf",
      "username": "user1",
      "data": "abc"
    },
    {
      "id": "tiyuykuy",
      "username": "user1",
      "data": "xyz"
    },
    {
      "id": "tryehhrt",
      "username": "user2",
      "data": "tyu"
    }
  ]

I'd like to query all the records for username: "user1" and get all the records for that user in an array.

I've tried the default:

const user = await db.get('records')
.find({ username: "user1" })
.value();

return user;

but it only finds the first record in the db.

What's the correct way to find multiple records in lowdb?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

NOTE: I don't use LowDB

Judging by the docs, I think it's not possible to find multiple records in LowDB. Instead, you can use the Array#filter method.

// Assuming the following returns an array of your object
const users = await db.get('records')
    .value();

// We can `filter` the user(s)
const result = users.filter(
    user => user.username === 'user1' /* or any other username */
);
about 4 years ago · Juan Pablo Isaza Relatório

0

Use filter instead of find .

const users = await db('records').filter({ username: "user1" });

Ref: https://github.com/typicode/lowdb/issues/185 Left join with lowdb

Multipe filters means use chain() as well

about 4 years ago · Juan Pablo Isaza Relatório
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