I have this code that runs to fetch data from a firebase collection: Basically I am fetching all the docs of collection ‘chatLists’ and seeing if an array called “users” which has two users includes the current users name who’s using the app, if they do, I return them all and all the filtered docs get inputed inside the chattingLists
Tag: google-cloud-firestore
What is the best way to reduce firestore document reads in chat app on page load?
I have a chat app that is charging me a large number of reads for each page load, 1 for each message to show. I’m trying to figure out a way to reduce that number and optimize for cost, as refreshing the page a few times costs hundreds of reads. The firestore pricing documentation says For queries other than document
Firebase Functions Finished with status: error
I am writing my first Firebase Function that is supposed to make a collection with a document inside (in Firestore) when a new user registers. The only logs I am getting are the following: Function execution started and Function execution took 194 ms. Finished with status: error. The versions of the dependencies: This is my code: When I tried outputting
ReactJS/Firestore: how to get the id of a newly created document
Using ReactJS and firebase, I’m trying to create a new document with sub-collections, so I need (I believe) to get the id of the document in order to reference the correct path to add the sub collections : Here is my Firestore : I created the collection “general_info” manualy, I’m trying to do it with code. Answer The addDoc() returns
Use firebase onSnapshot() in for loop?
The below code works for getting my data from firestore. I’m trying to update this to use onSnapshot() instead of of get(). Maybe the core of my confusion is onSnapshot() doesn’t return a promise and I’ve tried just adding the listeners into an array but it seems the data doesn’t get updated. How do I iterate over a for loop
Firestore onSnapshot with “where” and “orderBy” not matching any documents
I am struggling to figure out why the following code produces the “doc.empty” console log. The screenshot shows what I see in Cloud Firestore’s data console. My abbreviated code is below. In my example, I have the following variables: Why would this not match my data? Answer The problem is here: The screenshot shows that your custnum field has a
Uncaught (in promise) FirebaseError: Expected type ‘rc’, but it was: a custom ac object
The error happens in this code: ** I am trying from 2 days but can’t understand what’s the problem !!** I am trying to add an array in firebase , i am tring so many solution but can’t get what’s the problem !! Answer The setDoc() function takes a DocumentReference as first parameter but you are passing a CollectionReference. If
Unable to set state after getting document data from Firestore
I am trying to do a User Profile page and after getting the data from Firestore, I’m unable to set the data into the userProfile state. I got this error: The console log shows that the userProfile state is undefined, however, I can retrieve the data from Firestore without any issues as shown in the console log. Answer Instead of
Multiple orderBy() in Firestore Query Produces Error
I want to query Firestore db and order by two fields. Official docs suggest I can simply combine the orderBy statements via orderBy(‘field1’).orderBy(‘field2’) but when I run similar code, I get the following error in console: Project.js:62 Uncaught (in promise) TypeError: (0 , firebase_firestore__WEBPACK_IMPORTED_MODULE_0__.orderBy)(…).orderBy is not a function My code: Why am I getting this error? Answer You’re mixing the
How to merge duplicate Firestore documents?
I want to create a function that loops through an array and creates a new document in the Firestore database with an id and quantity fields for each element in the array but I want the function to merge the documents if the another document with the same id already exists I tried the following code: but it did not