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

163
Vistas
How do you find a document by its ID using version 9 of the Firebase JS SDK?

The new version 9 of the Firebase JS SDK has arrived with a more modular approach, and I'm trying to wrap my head around it.

I want to find and read a document from Firestore by its ID. In version 8, you could do:

await db.collection('users').doc(id).get();

Version 9 seems to have a function called "doc", and one called "getDoc", that could sound like the new equivalent, but I don't understand how to use them in practice. Has someone else played around with these yet?

Thanks in advance!

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

0

The documentation has a complete code snippet explaining how to fetch a single document with given ID:

import { doc, getDoc } from "firebase/firestore";

const docRef = doc(db, "users", id);
const docSnap = await getDoc(docRef);

if (docSnap.exists()) {
  console.log("Document data:", docSnap.data());
} else {
  // doc.data() will be undefined in this case
  console.log("No such document!");
}

The doc() method is used to get a DocumentReference and getDoc() is used to fetch the document from given reference.

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