Created
May 7, 2019 21:52
-
-
Save dmcgrath/c3665c2c655c595f1e2ee527e2973737 to your computer and use it in GitHub Desktop.
Collection Group Queries - Query Sample Data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Query example call center data | |
# Demonstrates both collection queries and collection group queries | |
# Data generated via https://gist.github.com/dmcgrath/0c404b5f2f17f1383e4f14631e579783 | |
from google.cloud import firestore | |
db = firestore.Client(project="<your project id here>") | |
review_calls = db.collection_group(u'calls').where(u'sample',u'<',5).limit(5) | |
call_docs = review_calls.get() | |
for call_doc in call_docs: | |
print(u'Review: Agent Call: {} => {}'.format(call_doc.reference.path, call_doc.to_dict())) | |
# If a reviewed call had a bad rating, display several more calls from that agent | |
if call_doc.get('rating') <= 2: | |
agents_calls = call_doc.reference.parent.limit(5).get() | |
for agent_doc in agents_calls: | |
print(u'List: Agent Calls: {} => {}'.format(agent_doc.id, agent_doc.to_dict())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment