javascriptfirebasegoogle-cloud-firestore

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?


Solution

  • Try this:

    db.collection('books').doc('fK3ddutEpD2qQqRMXNW5').get()
    

    (The first query is looking for an explicit user-set field called 'id', which probably isn't what you want.)