Skip to content

Instantly share code, notes, and snippets.

View dmcgrath's full-sized avatar

Dan McGrath dmcgrath

View GitHub Profile
; function findItem() { ;
; var item ;
; while(item_not_found) { ;
// search
; } ;
; return item ;
; } ;
; var item = findItem() ;
from google.cloud import firestore
from time import sleep
# Add a new document
db = firestore.Client()
doc_ref = db.collection(u'live_news').document(u'2019-01-31')
def pad_message(m):
pad_size = len(m)
return u'\u00A0'*pad_size + m + u'\u00A0'*(pad_size+1)
@dmcgrath
dmcgrath / gist:0c404b5f2f17f1383e4f14631e579783
Last active May 25, 2019 12:31
Collection Group Queries - Generate Sample Data
# Create example call center data
# Each agent has their own subcollection of calls
# You can run this generator multiple times in parallel
from google.cloud import firestore
import random
# Default values create 5000 documents.
MAX_AGENTS = 100
MAX_CALLS = 50
MAX_RATING = 5
@dmcgrath
dmcgrath / gist:c3665c2c655c595f1e2ee527e2973737
Created May 7, 2019 21:52
Collection Group Queries - Query Sample Data
# 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: