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

196
Vistas
Add document with auto-generated ID in sub collection?

I'm trying to add a document with auto-generated ID in reviews/something using:

await addDoc(collection(dbFirestore, "reviews", route.params.id), {
  rating: rating,
  text: text,
  user: {
    id: user.id,
    username: user.username,
    avatar: user.avatar,
  },
});

But I get:

Invalid collection reference. Collection references must have an odd number of segments, but reviews/XXX has 2.

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

0

Assume reviews is a collection and want to add a document (with auto generated id) to its subcollection

await addDoc(collection(dbFirestore, "reviews/document_id/subcollection"), {
  rating: rating,
  text: text,
  user: {
    id: user.id,
    username: user.username,
    avatar: user.avatar,
  },
});
about 4 years ago · Juan Pablo Isaza Denunciar

0

As the error says, a CollectionReference must have odd number of path segments but you have 2. You just need to specify the collection name so try refactoring the code as shown below:

// i.e. remove route.params.id
await addDoc(collection(dbFirestore, "reviews"))
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