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

953
Vistas
(Firebase Firestore)TypeError: n.indexOf is not a function

I'm trying to add another field value in a document but firebase returns TypeError: n.indexOf is not a function. Here's the code:

async function linkLCSN(cor, sn) {
  try {
    await setDoc(doc(db, "cor", cor), {
      sn: sn,
    }, {merge: true});
  } catch(e) {
    console.error(e);
  }
} 

I've already succeeded in doing this way but I don't know why this time it keeps giving me this error. This is the working code:

async function submitToDatabase(name, email, cor, cs, cn, concern) {
    try {
        //Set Datas 
        await setDoc(doc(db, "cor", cor), {
        name: name,
        email: email,
        cor: cor,
        courseSection: cs,
        contactNumber: cn,
        isViewed: false,
        timestamp: serverTimestamp(),
        }, {merge: true});
        const docRef = await addDoc(collection(db, "cor", cor, "concerns"), {
        concernData: concern,
        });
        console.log("Yung betlog nasa:" + docRef.id);
        //Do page changes
        let a = document.querySelector(".concern-main-container");
        let b = document.querySelector(".concern-preview-container");
        a.style.display = "none";
        b.style.display = "block";
    } catch(e) {
        console.error(e);
        //Custom Alert
    }
}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

I'm assuming you are using v9 of firebase (modular version). It may sound silly, but make sure that you have initialized your app and that you are using a valid reference to a collection.

For example:

import { initializeApp } from 'firebase/app';
import { getFirestore } from 'firebase/firestore';

const config = {/** your firebase config properties **/};

const app = initializeApp(config);
const db = getFirestore(app);

Then to add a new document, you can do:

const createDocument = (collectionName, document) => {
    const colRef = collection(db, collectionName);
    return addDoc(colRef, document);
};

Remember the addDoc function returns a promise, so be sure to handle this is the caller of createDocument

about 4 years ago · Juan Pablo Isaza Denunciar

1

I solved my problem by checking every type of params that passing to doc(), that params should not be Integer. It must be String

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