1

I'm trying to listen to a firebase collection for a document creation.

The firebase documentation lays it out like this:

# Create a callback on_snapshot function to capture changes
def on_snapshot(col_snapshot, changes, read_time):
    print(u'Callback received query snapshot.')
    print(u'Current cities in California:')
    for doc in col_snapshot:
        print(u'{}'.format(doc.id))

col_query = db.collection(u'cities').where(u'state', u'==', u'CA')

# Watch the collection query
query_watch = col_query.on_snapshot(on_snapshot)

Instead of u'state' inside of the where(), is there some way to reference the document title? (The title is not present within the document)

I've tried using u'__name__' but get the error:

RuntimeError: Error 3: a filter on __name__ must be a document resource name

1 Answers1

0

The JavaScript SDK seems to have an explicit options for it as shown here:

db.collection('books').where(firebase.firestore.FieldPath.documentId(), '==', 'fK3ddutEpD2qQqRMXNW5').get()

So firebase.firestore.FieldPath.documentId() indicates the document ID.

There is no direct equivalent in Python, but you can accomplish the same by querying on __name__, which is the internal name of that field:

col_query = db.collection(u'cities').where(u'__name__', u'==', u'your_document_id')
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807