Open lsoaresesilva opened 11 months ago
class City: def __init__(self, name, state, country, capital=False, population=0, regions=[]): self.name = name self.state = state self.country = country self.capital = capital self.population = population self.regions = regions @staticmethod def from_dict(source): # ... def to_dict(self): # ... def __repr__(self): return f"City(\ name={self.name}, \ country={self.country}, \ population={self.population}, \ capital={self.capital}, \ regions={self.regions}\ )" import firebase_admin from firebase_admin import credentials from firebase_admin import firestore # Use a service account. cred = credentials.Certificate('path/to/serviceAccount.json') app = firebase_admin.initialize_app(cred) db = firestore.client() cities_ref = db.collection("cities") query_start_at = cities_ref.order_by("population").start_at({"population": 1000000}) # ou docs = ( db.collection("cities") .where(filter=FieldFilter("capital", "==", True)) .stream() ) for doc in docs: print(f"{doc.id} => {doc.to_dict()}")