Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query firestore database for document id

I want to query a firestore database for document id. Currently I have the following code:

db.collection('books').where('id', '==', 'fK3ddutEpD2qQqRMXNW5').get() 

I don't get a result. But when I query for a different field it works:

db.collection('books').where('genre', '==', 'biography').get() 

How is the name of the document id called?

like image 1000
Developer Avatar asked Dec 18 '17 21:12

Developer


People also ask

What is firestore document ID?

On this page. Inherited Method Summary. public abstract @interface DocumentId implements Annotation. Annotation used to mark a POJO property to be automatically populated with the document's ID when the POJO is created from a Cloud Firestore document (for example, via toObject(Class) ).

How do I get specific data from firestore?

There are two ways to retrieve data stored in Cloud Firestore. Either of these methods can be used with documents, collections of documents, or the results of queries: Call a method to get the data. Set a listener to receive data-change events.

Is firestore document ID unique?

Correct, it is extremely unlikely, but not guaranteed.


1 Answers

I am a bit late, but there is actually a way to do this

db.collection('books').where(firebase.firestore.FieldPath.documentId(), '==', 'fK3ddutEpD2qQqRMXNW5').get() 

This might be useful when you're dealing with firebase security rules and only want to query for the records you're allowed to access.

like image 138
Denys Mikhalenko Avatar answered Oct 06 '22 05:10

Denys Mikhalenko