Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

252
Views
TypeError: listingsRef.add no es una función. (En 'listingsRef.add(updatedUploadObjects)', 'listingsRef.add' no está definido)

Estoy desarrollando una aplicación de listado y uso firebase como mi back-end, antes de agregar la declaración .orderBy para ordenar los datos creando la fecha, todo funciona bien y puedo actualizar la nueva publicación en la aplicación, pero después de agregar .orderBy( 'createdAt', 'desc') en el listado, no puedo actualizar ninguna publicación nueva y hay un error "TypeError: listingsRef.add no es una función. (En 'listingsRef.add(updatedUploadObjects)', 'listingsRef.add ' no está definido) el código se muestra a continuación:

 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')

y esto:

 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 answers
Answer question

0

Esto define una CollectionReference :

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

Si revisa ese enlace, verá que una CollectionReference tiene un método de add , lo que significa que puede agregarle un documento.


Esto define una Query :

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

Si revisa ese último enlace, verá que una consulta no tiene un método de add , por lo que no puede add algo a una consulta.


Querrá mantener la CollectionReference también, para que pueda llamar a add() en eso.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!