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

106
Vistas
Firestore Query Raises Exception if Including orderBy

I have the following function:

async function loadGalleryImages2() { // load images for gallery
    const collectionRef = db.collection('projects').doc(project.id).collection('images')
    const docQuery = query(collectionRef, orderBy('displayOrder'))
}

where the declaration of docQuery causes the following error to appear in console:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'startAt')

If I remove the orderBy parameter as shown below, I do not get any error.

async function loadGalleryImages2() { // load images for gallery
    const collectionRef = db.collection('projects').doc(project.id).collection('images')
    const docQuery = query(collectionRef)
}

The firebase docs show similar examples so I'm not sure why this is causing errors.

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

0

Upon checking your code, you've used both the web version 9 (modular) and web version 8 (namespaced). I replicated your code and was able to get the same error: enter image description here

Moving forward, you must only choose one version between the two. Also, check this guide for more information in upgrading from version 8 to modular (version 9) Web SDK.

I've tried your code for both modular and namespaced using the code below:

For namespaced (web version 8):

async function loadGalleryImages2() { // load images for gallery
    const collectionRef = db.collection("projects").doc(project.id).collection("images").orderBy("displayOrder");
    collectionRef.get()
    .then((querySnapshot) => {
        querySnapshot.forEach((doc) => {
            // doc.data() is never undefined for query doc snapshots
            console.log(doc.id, " => ", doc.data());
        });
    })
    .catch((error) => {
        console.log("Error getting documents: ", error);
    });
}

And for modular (web version 9):

// Add this in your import statement if you choose to use modular version
import { getFirestore, collection, query, getDocs, onSnapshot } from "firebase/firestore";

async function loadGalleryImages2() { // load images for gallery
  const querySnapshot = await getDocs(collection(db, "projects", project.id, "images"), orderBy("displayOrder"));
  querySnapshot.forEach((doc) => {
    // doc.data() is never undefined for query doc snapshots
    console.log(doc.id, " => ", doc.data());
  });
}
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