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

412
Vistas
Why getting Invalid collection reference error?

I am updating a document in firebase when user enters a comment.The code for the same is:

 const docRef=collection(db,"posts",post.id);
        console.log(docRef);
        updateDoc(docRef,{
          user:localStorage.getItem('Name'),
          title: post.title,
          comment:temppost ,
          upVotesCount: 0,
          downVotesCount: 0,
          createdAt: post.createdAt,
          updatedAt: date.toUTCString(),
          isCommentVisible:false
        });

But I m getting this error:

Uncaught (in promise) FirebaseError: Invalid collection reference. Collection references must have an odd number of segments, but posts/PQAvoGjUeX8aPVVZxMNC has 2.

I haven't used any subcollections here.

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

0

You need a DocumentReference to update a single document that you can create using doc(). The collection() is used to create a CollectionReference:

// use doc() instead of collection()
const docRef = doc(db,"posts",post.id);

Also checkout: Firestore: What's the pattern for adding new data in Web v9?

about 4 years ago · Juan Pablo Isaza Denunciar

0

You are trying to pass a document in a collection function. (db,"posts") is how you refer to a collection and (db,"posts",post.id) is how you refer to a document. So use one of these:

const docRef = doc(db,"posts",post.id);    // 3 arguments for a document
------
const postsRef = collection(db,"posts");   // 2 arguments for a collection
const docRef = (postsRef,post.id);         // in essence 2+1 arguments for a document
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