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

256
Vistas
TypeError: listingsRef.add is not a function. (In 'listingsRef.add(updatedUploadObjects)', 'listingsRef.add' is undefined)

I'm developing a listing app, and using firebase as my back end, before I add .orderBy statement to sort the data by creating date, everyting works fine and I can update new post on the app, but after I add .orderBy('createdAt', 'desc') in the listing, I can not update any new post and there is a error "TypeError: listingsRef.add is not a function. (In 'listingsRef.add(updatedUploadObjects)', 'listingsRef.add' is undefined) the code is shown below:

    import { setFavoriteItems } from '../../../favorites/redux'
import { firebase } from '../../../api/firebase/config'
import ServerConfiguration from '../../../../ServerConfiguration'

const savedListingsRef = firebase
  .firestore()
  .collection(ServerConfiguration.database.collection.SAVED_LISTINGS)
  .orderBy('createdAt', 'desc')
const listingsRef = firebase
  .firestore()
  .collection(ServerConfiguration.database.collection.LISTINGS)
  .orderBy('createdAt','desc')
const ListingCategoriesRef = firebase
  .firestore()
  .collection(ServerConfiguration.database.collection.CATEGORIES)
  .orderBy('order')

and this:

 if (selectedItem) {
    listingsRef
      .doc(selectedItem.id)
      .update({ ...updatedUploadObjects, photo: coverPhoto })
      .then(docRef => {
        callback({ success: true })
      })
      .catch(error => {
        console.log(error)
        callback({ success: false })
      })
  } else {
    listingsRef
      .add(updatedUploadObjects)
      .then(docRef => {
        if (docRef.id) {
          listingsRef
            .doc(docRef.id)
            .update({ id: docRef.id, photo: coverPhoto })
        }
        callback({ success: true })
      })
      .catch(error => {
        console.log(error)
        callback({ success: false })
      })
  }
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This defines a CollectionReference:

const savedListingsRef = firebase
  .firestore()
  .collection(ServerConfiguration.database.collection.SAVED_LISTINGS)

If you check that link, you'll see that a CollectionReference has an add method, meaning that you can add a document to it.


This defines a Query:

const savedListingsRef = firebase
  .firestore()
  .collection(ServerConfiguration.database.collection.SAVED_LISTINGS)
  .orderBy('createdAt', 'desc')

If you check that last link, you'll see that a query doesn't have an add method, so you can't add something to a query.


You'll want to keep the CollectionReference around too, so that you can call add() on that.

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