0

Im trying to update the field "creator" to be an empty string in a document in react native with firestore but it does not work

firebase.firestore().collection("Users").where("creator","==",currentUserMail).where("user","==",childMail).limit(1).update({creator:""});
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
user123456
  • 171
  • 11
  • What issue you are facing? – Jignesh Mayani Apr 06 '21 at 11:00
  • I have this error : [Unhandled promise rejection: TypeError: firebase.firestore().collection("Users").where("creator", "==", currentUserMail).where("user", "==", childMail).limit(1).update is not a function. – user123456 Apr 06 '21 at 11:04
  • as per the docs, we can't use the update method of firestore when we use the limit feature. please refer to the rnfirebase docs for more details you have to find another way to update your desired values. – Jignesh Mayani Apr 06 '21 at 11:17
  • And can I use update with where clause? – user123456 Apr 06 '21 at 11:30
  • You can only update a known document reference. You need to get a query using where, to return all of the documents and then use `update` to update each of them individually. If this is a bulk function, you will be better off doing this in Cloud Functions, in batches of <= 500 – Jason Berryman Apr 06 '21 at 11:30
  • Not sure if you did, but when chaining `.where()` clauses like that, you need to add it as an index in the firebase console. – cpboyce Apr 06 '21 at 13:43
  • Firestore doesn't support update queries, where you pass a condition and an operation to the server in one go. You'll need to 1) execute a query, 2) loop over the results, 3) update each in turn. – Frank van Puffelen Apr 06 '21 at 16:14

0 Answers0