Firestore id naming convention [duplicate] - firebase

This question already has answers here:
Firestore query documents with only collections inside
(2 answers)
Closed 5 years ago.
Is there any naming convention for document id in FireStore. I created some documents inside a collection with the date in "yyyy-mm-dd" as the id. When i try to get all documents inside the collection i got the snapshot size as zero. When I put a dummy doc with test as id I got only the test doc not the other docs.
My document structure

The contraints can be seen here Quotas and Limits if you scroll down to the bottom you will find contraints on ids, paths and field names.

Related

Firestore Documents Template [duplicate]

This question already has answers here:
Firebase Firestore: Is there a way to enforce required fields for all documents in a collection?
(3 answers)
Closed 2 years ago.
I'm creating a Firestore Database that has a "devices" collection then each device has its own document. I already have a device with various fields.
Is there any way I can create a template where the document fields remains the same for all documents and I can just fill in the values upon adding a new device from the Firebase console?
Documents in Firestore only contain exactly what you put in there. There are no "default" or "understood" fields. If you want a document field to contain some value, you will have to write it into each document.

Does firebase batch writes needs to know the specific documents before hand? [duplicate]

This question already has answers here:
Can Firestore update multiple documents matching a condition, using one query?
(8 answers)
Updating documents in Cloud Firestore based on a query
(2 answers)
Closed 2 years ago.
i need to update a field in some documents of my users collection, after another document changes, only if those users meet a required criteria. I know i can do querys filtering for the criteria but this would download the documents (i dont need this) i just need to update the field changed in the first document.
is this even posible or should i look for another aproach?
You must know the full path of every document in order to update it. There is equivalent of SQL's "update where" type queries that will both query and update the matching rows. You will need to query first, iterate the results, and update what you need from that set.

flutter:get the last document from firebase [duplicate]

This question already has an answer here:
Get last created document in a Firebase Firestore collection
(1 answer)
Closed 2 years ago.
i have many document inside a collection of firebase. But i want to retrieve only the last document which is present at the bottom. You can see the image . i want to retrieve the highlighted document
You can use last in following way to get last document.
Firestore.instance.collection("data").snapshots().last
This will give you only last element.

Firestore sub collection querying data [duplicate]

This question already has answers here:
How to list subcollections in a Cloud Firestore document
(4 answers)
Closed 5 years ago.
I am reading the docs and see that FireStore allows sub-collection. Which is great. Consider the following example as mentioned here int he docs.
As shown in the docs I can get the reference to the last doc as follows
var messageRef = db.collection('rooms').doc('roomA')
.collection('messages').doc('message1');
In the above example, the id's for docs and collections are typed in.
There are cases when id's are dynamically generated. In such a case how can I know how many collections a doc has? Or whether a doc has any sub-collections. How can I do that?
On mobile clients, you can't know how many collections or what collections a document has. There is just no API for that. You have to know ahead of time what collections may exist for a document, or accept that a query on an unknown subcollection may return no documents.

Get Only documents names in Firestore [duplicate]

This question already has answers here:
How to get a list of document IDs in a collection Cloud Firestore?
(4 answers)
Closed 5 years ago.
Is it possible to get only documents name as a String array without retrieving any collections? I couldn't find any documentation about it.
There is no API to retrieve only the document names in the SDKs. But the REST API has a list call that seems to do precisely that.

Resources