Query firestore database for document id

后端 未结 6 664
梦毁少年i
梦毁少年i 2020-12-01 03:09

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

db.collection(\'books\').where(\'id\', \'==\', \'fK3ddutEpD2qQqRMX         


        
6条回答
  •  [愿得一人]
    2020-12-01 03:55

    You can use the __name__ key word to use your document ID in a query.

    Instead of this db.collection('books').doc('fK3ddutEpD2qQqRMXNW5').get() you can write

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

    In this case you should get an array of length 1 back.

    The firebase docs mention this feature in the rules documentation. https://firebase.google.com/docs/reference/rules/rules.firestore.Resource

提交回复
热议问题