Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

169
Vistas
Check if a key exists without getting all node data

I am using Firebase's Realtime Database with node and I find that the only way to check that a key exists is to return all the data

{
  "salas" : {
    "sala01" : {
      "activa" : true,
      "fechaComienzo" : "2021-10-16 07:09:00Z",
      "fechaCreacion" : "2021-10-16 07:09:24Z",
      "nombre" : "test",
      "masInfo": {
        ...
      }
    },
    "sala02" : {
      "activa" : true,
      "fechaComienzo" : "2021-10-16 07:09:00Z",
      "fechaCreacion" : "2021-10-16 07:09:24Z",
      "nombre" : "test",
      "masInfo": {
        ...
      }
    }
  }
}
async function checkExists(_ref, key) {
    const q = query(_ref, ...[orderByKey(), equalTo(key)])
    const datos = await get(q);
    console.log('@info', q, datos);
    return datos.exists();
}

const _ref = ref(getDatabase())
checkExists(_ref, 'sala01')

With the above example, if I want to know if sala01 exists, it brings me every node with its descendants.

I wonder if there is any other way to simply check if sala01 exists without bringing me the entire node or if there is some trick to bring a node with a depth as if I have seen in the REST API documentation, shallow

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This sort of query is more complex than needed:

const q = query(_ref, ...[orderByKey(), equalTo(key)])

If you know the key of a node already, you don't need to use a query, but can access that key directly.

async function checkExists(_ref, key) {
    const ref = child(_ref, key)
    const datos = await get(ref);
    return datos.exists();
}

This won't read read the entire /_ref node, but will read the entire /_ref/$key node. There is no way to test for the existence of a path without reading that path.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda