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

254
Vistas
How do I add Firestore to my Javascript code?

In Javascript, I've been trying to add Firestore using the code below:

import { initializeApp } from "https://www.gstatic.com/firebasejs/9.0.2/firebase-app.js";
import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.0.2/firebase-analytics.js";
import { getFirestore } from "https://www.gstatic.com/firebasejs/9.0.2/firebase-firestore.js";

const firebaseConfig = {
    apiKey: "XXXXX",
    authDomain: "XXXXX",
    projectId: "XXXXX",
    storageBucket: "XXXXX",
    messagingSenderId: "XXXXX",
    appId: "XXXXX",
    measurementId: "XXXXX"
};

const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
const db =  getFirestore();   

db.collection("users").where("uid", "==", "1234")
.onSnapshot((snapshot) => {
    snapshot.docChanges().forEach((change) => {
        console.log("change ", change.doc.data());
    });
});

However, I get the following error:

Uncaught TypeError: db.collection is not a function

Please help, thanks.

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

0

You are using modular version so try refactoring the onSnapshot to this syntax:

import { collection, query, where, onSnapshot } from "https://www.gstatic.com/firebasejs/9.0.2/firebase-firestore.js";

const q = query(collection(db, "users"), where("uid", "==", "1234"));
const unsubscribe = onSnapshot(q, (querySnapshot) => {
  const documents = [];
  querySnapshot.forEach((doc) => {
      documents.push(doc.data().name);
  });
});
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