I have the following code in my client and I understand now that Date.now() works and new Date() does not, but for future errors is there any way for me to see these errors in some firebase log?
userList.push({'loggedIn': new Date()}).catch(function(error){
console.log('err')
console.log(error) //nothing showed here.
})
I ran firebase functions:log but got No log entries found.
https://firebase.google.com/docs/storage/web/handle-errors
If I understand correctly, you want to be informed that a value that you store in the realtime Database was null (or erroneous). The easiest way would be to look at the data through the Firebase console. Be aware that Firebase cannot, by default, detect that YOUR DATA is erroneous from a value perpective.
The command you ran (firebase functions:log) is about Cloud Functions and is not about logging for Realtime Database.
Similarly, the link you provided is about Storage and not about logging for Realtime Database.
Related
I have an app connected to google firebase realtime database. I want to test google cloud functions as a server for running backend functions triggered once every day or triggered by data changed in the database.
I have an emulator instance running locally with a typescript function that I wrote.
I have the realtime database running, connected to the app and working well.
Now when I change data in the database, the functions are not being triggered.
function in index.ts:
import * as functions from "firebase-functions";
exports.simpleDbFunction = functions.region('europe-west1').database.ref('/some path in the database')
.onCreate((snap, context) => {
console.log("functions triggered by datachange:", snap.val())
});
the firebase project is connected to the correct project (using the interface in the terminal).
the app and realtime database are currently working and I can see changes in the data inside the firebase console.
What am I missing?
I've also tried the more complicated example from google's documents (makeUppercase function). But when it didn't work I went back to a simple function that is triggered on data creation and prints to the console.
Edit: I notice that in the emulator UI the real time database is empty. Shouldn't it connect to the real time database of the app? isn't that why I connected the emulator to a specific project?
Edit2: I tried changing the function line to:
functions.region('europe-west1').database.instance("the URL of the
rtdb").ref(...
and I get an error saying that the event function has malformed resource member
So I kinda solved it:
I found out that you can't really connect from a local emulator to the production environment of your actual google firebase. (Which is kinda weird, you have to commit to this technology even before you had a chance to see any code in action) <-- fix me if I'm wrong about this
If you use realtime database cloud functions you can't use any region other than 'us-central1'. as mentioned in this document:
https://firebase.google.com/docs/functions/locations
You can connect your app to the local emulator on your machine!
Get your database instance:
FirebaseDatabase database = FirebaseDatabase.getInstance();
Add the following line in your app (which is weird) before the first database operation:
database.useEmulator("10.0.2.2", 9004);
change 9004 to your local realtime database port.
I have more than 52k hits on my small project which is using NextJS with Firebase 9.
I don't know what the problem is because the data I am using is very limited and I have only two snapshot listener and one Authentication feature. But somehow in just two days Firestore quota has exceeded and there are more than 52k READ hits.
I don't know why that happened because there are no memory leaks and I am also closing the API listeners which come attached with Firebase.
I am providing github link in case anyone wants to take a look https://github.com/jainChetan81/Todo-List
Attached screenshot of Firebase console:
Use of the Firebase console will incur reads. If you leave the console open on a collection or document with busy write activity then the Firebase console will automatically read the changes that update the console's display. Most of the time this is the reason for unexpected high reads. You can go through this answer. Also, currently there are no tools to trace the reads in Firestore. So to limit the Firestore database reads you have to configure security rules.
So, I would suggest you check your Firestore rules. And if not, it is better to contact Firebase Support as this kind of issue needs visibility into your project and they will have access to it.
I am having the same problem as you with my React app. The solution is to use the useEffect hook and call the function that requests for firestore collection;
useEffect(()=> {
getPosts();
}, []);
In the last day, I have started having trouble with Cloud Firestore serving outdated data to my Flutter app running on android. I tried clearing the cache for the app, uninstalling/reinstalling with no success. Still Firestore kept serving the outdated data. Then I tried disabling persistence with the persistenceEnabled: false at startup. It stopped serving the outdated data, but now it doesn't return current data that should be returned! Any suggestions to check what might be going on?
Edit: I should mention that this is happening on a collectionGroup query for which the index has been built. I've checked the database rules, and there are not any denies or errors resulting from this query.
Turns out I changed one of my Collection group queries recently and needed to update the index. So if you have Cloud Firestore queries that are acting erratic like mine was, check out your logcat or console log for an error like this:
Unhandled Exception: [cloud_firestore/failed-precondition] Operation was rejected because the system is not in a state required for the operation's execution. If performing a query, ensure it has been indexed via the Firebase console.
Firestore is supposed to provide a URL to build the appropriate index, but in my case the URL did not appear so I had to add it manually.
I have an odd problem, which I'm hoping is either a misunderstanding on my part or a misconfiguration somewhere.
I am trying to use the Firebase Firestore web sdk to retrieve data. When I make read calls to Firestore in my webapp as an un-authenticated user, the reads return fine, as expected.
However, when I'm logged in as a user (either email/password auth or Facebook auth), I get an error:
Could not reach Firestore backend.
When I set the logging level to debug, I see this:
Firestore (4.8.1) 2017-12-24T01:08:15.146Z [PersistentStream]: close with error: FirebaseError: [code=unknown]: Fetching auth token failed: Cannot redefine property: refreshToken
Which seems highly related.
Has anyone else encountered this or have a sense of what may be going on?
Thanks!
While I run the command firebase deploy I get this error:
Error: HTTP Error: 400, Project 'my_project' is not a Firestore enabled project.
Are you trying to use Cloud Firestore?
If so, visit the database section of the console and initialize Cloud Firestore
If not, remove the firestore.rules file locally
I figured it out myself. It was just an ignorance while using the firebase console. I just had to enable the firestore beta from the console itself, under Database.
If you’re not using Cloud Firestore, comment firestore in firebase.json
I had the same problem. The solution is this: Go to Firebase console and login there [Firebase console]. Here you will see your Recent projects. Go to your project e.g. “stepintothepresent” and then go to database at left side panel, then choose cloud firestore and then I selected the 2nd option.
After that I run firebase deploy from command prompt and the result is this
You can enable the REST APIs using below URL:
https://console.cloud.google.com/apis/library?project=
selected Cloud Firestore while initial firebase setup?
Just go to console and enable Cloud Firestore.
When prompted for once you can select test mode to start off and later change it to private.
I had to create a DB environment and it worked fine after that. I'm using the realtime DB, not Cloud storage so it shouldn't have stopped it, anyway, its fixed.
someone with another answer please.
Are you trying to use Cloud Firestore?
If so, visit the database section of the console and initialize Cloud Firestore
* Can you post the url please?
If not, remove the firestore.rules file locally
*Error: Error reading rules file firestore.rules