Firestore Python: Get Multiple Documents

Apr 25, 2019
doc_refs = [db.collection('test').document('xxx'), db.collection('test').document('Gyxnw0vD4dTuCYM8gOTs')]docs = db.get_all(doc_refs)for doc in docs:    if doc.exists:        content = doc.get('created')        log.info(f"id=${doc.id}, content=${content}")    else:        log.info("not found")

NOTE: I believe this feature is only available for server client, not available for Android/iOS/Web

NOTE: Client.get_all

Documents returned by this method are not guaranteed to be returned in the same order that they are given in references.

If multiple references refer to the same document, the server will only return one result.

Though the documentation mentioned:

Yields: .DocumentSnapshot – The next document snapshot that fulfills the query, or None if the document does not exist.

I tested with firebase-admin == 2.16.0 which utilize google-cloud-firestore >= 0.31.0

  • the return documents iterator is never None, even when doc_refs is empty.
  • DocumentSnapshot is never None. If the document doesn't exist, check for DocumentSnapshot.exists.

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.