I have made a to-do list app using Firebase Auth and Firestore, and I would like to add an attach image feature, with which you can add images to tasks. I need to use a combination of Auth, Storage and Firestore but I'm not sure how to combine them.
How can I reach data from Firebase Storage using Firestore? Before I got into this, I was imagining it would be something like adding an imageLink field to each task, and then linking to the relevant image in Firebase Storage. Is it something similar? What should I do?
Firestore and Cloud Storage are two different services offered by Firebase. They don't communicate with each other. It's up to you to make the link between the different "entities" stored in this two services.
A very common approach for your Use Case is to first upload the file in Cloud Storage, and then save in a Firestore document, either the path of the file or a signed URL to the file (or both, knowing that with the path you can always generate a signed URL).
Another approach consists in getting a Firestore document ID (automatically generated with the addDoc() or setDoc() methods) and use this ID to rename the file before saving it to Cloud Storage. This way the link between the file and Firestore is clearly materialized and you can very easily link them in your front end. You could also use this approach to put in a given folder all the files linked to one Firestore doc: you name the folder with the Document ID.
A third approach is to use the metadata of the Cloud Storage file to store the ID of a Firestore document. Most of the time this approach is less "handy": You either need to know the path of a file or you need to list all the files in a bucket or folder in order to get the ID of the Firestore docs. But for some specific cases it can be an interesting approach, knowing that nothing prevents you to combine approach #1 or #2 with approach #3, if necessary...
Related
I'm making a whiteboard app using Flutter and Firestore.
This whiteboard app creates a room first, then creates pages, and then draws inside the page.
Firestore has the following configuration:
I need to be able to get the number of subcollections in Firestore to get the number of pages.
How do I get the number of these subcollections(pages)?
You can't get all collection from one doc in dart.
Retrieving a list of collections is not possible with the mobile/web client libraries. You should only look up collection names as part of administrative tasks in trusted server environments. If you find that you need this capability in the mobile/web client libraries, consider restructuring your data so that subcollection names are predictable.
Here is the document link.
There is no function that can return the number of sub-collections that exist within a document. If you need such a count, you need to create this mechanism yourself. But it's pretty simple, you can create a document in which you can increment/decrement a numeric value, each time a new sub-collection is added or deleted from the document.
Can anybody give me a hint ? If you need further information please write a comment.
For Autocomplete solutions, it's advisable to maintain a master list of all entries and keywords that would be searchable, in practice this can be all stored in an array in a single Firestore document - firestore document restrictions apply. You would maintain this with cloud functions based on your design and potentially cloud triggers.
With the new Bundle feature from Firestore, you can allow every client to have direct access to this information, it's only up to you to process the search input and compare it to the master document.
I’m developing an app in swift by using firebase in the back end.
I have successfully created a user by using the standard procedure as stated in the documentation.
My problem comes when I want to add the UID value to the database. I can’t. What I’m doing is getting the UID (userID) from the Auth().user (what I successfully do) and using the following code (I don’t have de computer do it can contain errors but I copy it from the documentation and I’m fact it compiles, the problem is that is does nothing
let ref = Database().database().reference()
self.ref.child(“users”).setValue(userID)
I have tried with the following
Self.ref.child(“users”).child(user.id).setValue(userID)
But it fails due to the fact that users have no children. The issue is that users is a collection and I don’t now if it works in the same way or not.
My intentions is to create the entry in the “users” collection in the database just after singing up a new user. (And to be able to layer erase it)
Thanks!
Firebase has two NoSQL databases:
the Realtime Database, which is the original JSON database.
Cloud Firestore, which is the newer document/collection database.
These two databases are both part of Firebase, but have completely separate APIs.
You speak about collections in your question, which are a Cloud Firestore concept. But your code uses the API of the Realtime Database. If you're looking to write data to Cloud Firestore, you'll want to use the API that is documented here.
I am creating a mobile app , and this mobile app works currently with one google fire store database.
I want to see this app to more than one customer and I don't want to make a collection for each customer.
Instead I want to open a new database.
I know that I need to import the JSON file for each database.
My Question:
Can I tell the app to use database one then if you login with another
account use database 2?
There is only a single Firestore database instance per Firebase project. There is (currently) no way to add additional Firestore database instances to a project.
So that means you'd have to have a separate project for each user. That part is technically feasible for databases, as you can dynamically create a FirebaseApp instance with the configuration data for the signed in user. The problem is that you need to first sign in the user (which requires that you already have a FirebaseApp instance for the project that this user is registered on.
I'd highly recommend reconsidering why you want to create a separate Firestore instance for each user, as creating user-specific sub-collections is by far the simplest way to implement a multi-user application on Firestore.
I'm currently developing a solution that lets users create a parent listing whereby they can upload files, assign child listings to that and then search their listings based on data from both the parent and child listings.
As an example, think of it as an inventory database. You create your parent listing for say a product, give it a name and upload some images of it. You then create your child listings which would be the stores that stock your product.
Your search capabilities would allow the user to search the product by free text, but also using parameters from the child listings, for example Price, In Stock, Tags etc.
I've tried to develop a concept using Firebase for this which utilises Auth, Storage and Functions, however due to the search limitations of Firestore, it cannot be done.
MongoDB offers something similar to Firebase' functionality whereby I can use Atlas which gives me all the search capabilities I need using Mongo instead of Firestore. In addition, they also have Stitch which provides the Cloud Function, Trigger and Auth functionality I need.
What they don't offer however is any Storage solution.
Does anyone know a way I can use MongoDB Stitch Auth, alongside Firebase Storage to integrate directly with the UI using the Firebase Storage security rules?
I know I could create a Stitch Function that handles the passing of file from UI to Firebase, however I'd prefer to go direct if possible.