'How to get specific fields for all documents from Firestore?

The following code returns skills field from GOOGL103 document only.

However I want to get skills field from all the documents in job collection, how do I do that?

import firebase_admin
from firebase_admin import credentials,firestore

cred = credentials.Certificate("service_key.json")
firebase_admin.initialize_app(cred)

job_keywords = firestore.client().collection(u'job').document('GOOGL103').get().to_dict()['skills']

print(f'Skills Required: {job_keywords}')


Solution 1:[1]

You could just query the collection and loop all the documents to get the specific fields. Check the code i wrote below:

docs = db.collection(u'job').stream()

for doc in docs:
    skills = u'{}'.format(doc.to_dict()['skills'])
    print(skills)

There are more sample snippets on Firestore documentation that you can use for your other use-cases. You may refer here for more information.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1