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

164
Vistas
How to send data from my code to firestore?

I am trying to add an array to my firestore database, but I can't seem to do so as it keeps giving me an error that ColRef.add is not a function. Help! Below shows two of my code snippets. One for firebase.js while the other is where I intend to send my data to firestore from. The array has no issues.

 onAuthStateChanged(auth, (user) => {
      if (user) {
        setUser(user.uid);
      } else {
        console.log("no user found")
      }
    })

    const colRef = collection(db, 'user_data');

    useEffect(() => {
      setSend([{
        averagepace: calculatePace(distance, seconds),
        distance: distance.toFixed(2),
        time: showTime(seconds),
        day: getDayname(),
        uid: user,
        picture:'https://media.wired.com/photos/59269cd37034dc5f91bec0f1/191:100/w_1280,c_limit/GoogleMapTA.jpg',
      }])
      console.log(send);
    }, [end]);

    const res = colRef.add(send);

// import all functions needed from the SDKS needed
import {initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";
import { getFirestore } from "firebase/firestore";
import { Firestore, getDoc, collection, getDocs,
  addDoc, deleteDoc, doc,
  query, where, onSnapshot

} from 'firebase/firestore';


const FIREBASE_APIKEY="AIzaSyD1Hk1asVux06fU55J3FaaYfyIUI4sM1B4"
const FIREBASE_AUTHDOMAIN="stressgo-3cef0.firebaseapp.com"
const FIREBASE_PROJECTID="stressgo-3cef0"
const FIREBASE_STORAGEBUCKET="stressgo-3cef0.appspot.com"
const FIREBASE_MESSAGINGSENDERID="316778582160"
const FIREBASE_APPID="1:316778582160:web:3502f9529218e8fc838815"
const FIREBASE_MEASUREMENTID="G-BLT8YK6SMG"

// Initialize Firebase
const firebaseConfig = {
    apiKey: FIREBASE_APIKEY,
    authDomain: FIREBASE_AUTHDOMAIN,
    projectId: FIREBASE_PROJECTID,
    storageBucket: FIREBASE_STORAGEBUCKET,
    messagingSenderId: FIREBASE_MESSAGINGSENDERID,
    appId: FIREBASE_APPID,
    measurementId: FIREBASE_MEASUREMENTID,
  }

  const app = initializeApp(firebaseConfig)
  export const auth = getAuth(app);
  export const db = getFirestore(app);
  

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

0

You're trying to use Firestore SDK v8 syntax instead of v9, which is what you have installed. Please refer to the v9 samples in the documentation and use the addDoc function instead.

addDoc(colRef, send)
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