How do I get the number of subcollectors in Firestore? - flutter

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.

Related

How can I retrieve files from Firebase Storage based on user?

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...

How to paginate data from multiple Firestore collections in Flutter?

I want to create a screen in my Flutter app to display all financing details that relate to a specific user. Each kind of financial entry has its own collection on Firestore.
To elaborate more, I have a purchases collection and a transactions collection. A user should be able to see both of these collections together in a single view sorted by date or money-spent, which means (I think) I have to "join" these two collections (like in SQL) and display the result.
The question now remains how can I paginate this data? As far as I know, I can't "join" collections in Firestore, and as far as I have searched I can't really paginate data from multiple collections simultaneously.
If you want to show a paginated view of the data from two collections, you will need to load the full page of data from both collections, merge them in your application code, and discard any data that is more than the page size you want to show.
In cases like this always consider whether you can instead create an additional collection where you store the data from both collections, and read from there. While data duplication is frowned upon in relational data modeling, it is very common in NoSQL databases.
To learn more about the topic, I recommend reading NoSQL data modeling and then watching Todd's excellent Getting to know Cloud Firestore.

Flutter TextFormField should give suggestions based on data in firebase

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.

Searching WITHIN a single doc - Firestore

I know that you can query a collection in Cloud Firestore to get documents that contain a certain field. However, is there a way where I can query/search WITHIN an already obtained document?
I am using it for a web app.
I know this question is a little vague and I have not provided any code, so I would be willing to provide clarification if needed.
Firestore doesn't provide a way to search the contents of a document snapshot that you already have. You will have to provide code to scan its field values yourself.

how to share a document to more than one users in mongodb with meteor

I want to save a document to a collection in MongoDB.
I have users collections provided by accounts-ui and accounts-password in meteor.
I would like to save documents that owned by multiple users.
I know I can do this using insert function. But I would like to know what is the better way to do this? How can I do this?
For example, the user created an object and save it to the collection. Then the user will share it to other users.
This is a fairly broad question and therefore hard to answer. One approach could be to use the alanning:roles package which will allow you define roles, and also groups.
Your documents could be assigned to either a role or a group, and then the retrieval code can check their access in returning the documents.