I am using Firebase in my project, including Firestore.
The docs say when setting up Firestore to include firebase-firestore.js in addition to the normal firebase.js file.
Is this required? I included it, but am also looking to reduce dependencies whenever possible.
Yes, it's required. firebase.js contains common code for all Firebase products you might use.
Related
I cannot start project with yarn run dev and have this error:
FirebaseError: Analytics: "measurementId" field is empty in Firebase config. Firebase Analytics requires this field to contain a valid measurement ID. (analytics/no-ga-id).
I deleted yarn.lock file, added some extra variables to.env file. Where can I find measurementId? What might help in this kind of error? May be somebody have already faced with such problem. Thanks :)
This has nothing to do with your yarn lock file. Which client side sdk are you using for Firebase? Angularfire perhaps?
I assume you did put your firebase config in your environment file of your angular app. Just add the property "measurementId" to it with the correct value, and you are good to go. You can get this property in your Firebase project.
If your app uses the Firebase hosting and uses reserved URLs you are good to go since it automatically handles the configuration for your application. It seems it isn't your case.
You should add or update the config file to ensure the measurementId field is present. To find the config file go to Your apps card in your Project settings from the Firebase Console.
It can be useful as well: How to get the measurementId from the Firebase config?
Is it possible to use "Callable Functions" together with AngularFire2?
Since AngularFireModule already calls initializeApp, I am not sure how to follow the instructions here?
I guess I should not call initializeApp() multiple times?
AngularFire2 is built on top of the regular Firebase JavaScript SDK. That means that anything that's possible in the JavaScript SDK, is also possible from within AngularFire2. If the action is related to showing data from Firebase in UI elements, there may be a wrapper from AngularFire. But even if there is no wrapper, you can access the JavaScript SDK directly.
So: Yes, it is possible to invoke Callable Cloud Functions from AngularFire2. You should indeed only initialize the app once, unless you're trying to access multiple projects.
If you're having trouble making this work, post the minimal, complete code that reproduces where you're stuck.
Is it possible to generate Swagger Spec file from function comments in firebase cloud functions? If so, how can we do it?
I see the cloud functions code to be more like serverless, so wondering if this is possible.
I haven't found an automatic way, but there are plenty of libraries to choose from.
I'm using express and nodejs in my Firebase Function implementations, and for me,
Swagger doc generation can be implemented via the following libraries:
https://github.com/scottie1984/swagger-ui-express
https://github.com/Surnet/swagger-jsdoc
You can find other libraries at:
https://swagger.io/tools/open-source/open-source-integrations/
This will create a new HTTP endpoint, which will serve an HTML page of a swagger doc.
There is not an automatic way to do this at this time. I think you could build your own but seems like it would be a lot of work.
The new Firestore DB allows me to store GeoPoints. Is there a way to query based on them?
So for example if each of my collections documents got a location field of the type geopoint.
How can I get the closest 10 documents to an arbitrary coordinate?
The documentation doesn't seem to cover this. I tried stuff like this:
someRef.where('location', '>', geopoint).limit(10).get();
Obviously this doesn't make much sense but I'm just trying out some stuff here 😅
We haven't exposed geoqueries yet, so currently there isn't a way to do this.
Historically, the Firebase Realtime Database used geohashes in a library called GeoFire--but given that we plan to expose actual geoqueries in the near future, we haven't updated that library to Firestore. To learn how to do something similar yourself though, have a look at this video.
A new project has been introduced since #problemsofsumit first ask this question. The project is called GEOFirestore.
With this library you can perform queries like query documents within a circle:
const geoQuery = geoFirestore.query({
center: new firebase.firestore.GeoPoint(10.38, 2.41),
radius: 10.5
});
You can install GeoFirestore via npm. You will have to install Firebase separately (because it is a peer dependency to GeoFirestore):
$ npm install geofirestore firebase --save
You can link to it via cdn:
https://cdn.jsdelivr.net/npm/geofirestore#2.2.2/dist/geofirestore.min.js
You could let Algolia do the geo search with radius for you. All it would require is to build a cloud function that triggers on your wanted documents and sync them to Algolia.
Take a look at Geo Search https://www.algolia.com/doc/guides/searching/geo-search/
Also Firebase documentation advertises Algolia as a solution to complex searches here https://firebase.google.com/docs/firestore/solutions/search
Rather than use third party services like Algolia I would use the new library that came out for both iOS and Android that replicates GeoFire for Firestore. The new library, called GeoFirestore, is fully documented and well tested. I have used this library already in many demo projects and it seems to work perfectly. Give it a shot!
After scouting the net, i found this GeoFirestore library by chintan369 that you could use to query nearby geopoints. The queries are based on Firestore native queries. Just add below line into your build.gradle (project-level):
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Then add the library to your build.gradle (app-level):
dependencies {
implementation 'com.github.chintan369:Geo-FireStore-Query:1.1.0'
}
...and sync your project.
Visit https://medium.com/android-kotlin/geo-firestore-query-with-native-query-bfb0ac1adf0a for more.
I would like to use Firebase analytics for one of my library modules. I would like to program in such a way that configuration file (google-services.json) should be accessible from either client app folder or configure the same from the client side.
Is there a way I could implement the above mentioned scenario?
Thanks in advance.
You can initialize your library project configurations manually as below,
For more info, kindly refer working-with-multiple-firebase-projects-in-an-android-app
Also go-through how-does-firebase-initialize-on-android to understand; how the Firebase module is getting initialized by itself.
For Android apps using Firebase, there is a central FirebaseApp object
that manages the configuration for all the Firebase APIs. This is
initialized automatically by a content provider when your app is
launched, and you typically never need to interact with it. However,
when you want to access multiple projects from a single app, you'll
need a distinct FirebaseApp to reference each one individually. It's
up to you to initialize the instances other than the default that
Firebase creates for you.
FirebaseOptions options = new FirebaseOptions.Builder()
.setApplicationId("1:530266078999:android:481c4ecf3253701e") // Required for Analytics.
.setApiKey("AIzaSyBRxOyIj5dJkKgAVPXRLYFkdZwh2Xxq51k") // Required for Auth.
.setDatabaseUrl("https://project-1765055333176374514.firebaseio.com/") // Required for RTDB.
.build();
FirebaseApp.initializeApp(this /* Context */, options, "secondary");
Hope I've answered your question.
I've found interesting workaround. Try the following:
put your google-services.json to any sample app google provides for Firebase integration. Compile it.
Take a look on path app/build/generated/res/google-services/debug/values/ there should be generated values.xml file with bunch of strings mentioned in errors you described. Copy these strings to value.xml file of your project. That's it.