0

Is it possible to perform an additional 'where' when fetching a specific document?

Fetching a document based on an available key works perfectly:

db = firestore.client()
dockey = 'mykey'
doc_ref = db.collection(u'mydocuments').document(u'%s' % (dockey))
doc = doc_ref.get()

But I want to limit my reads, so I only want the document that correspond to an additional 'where' statement. I would expect something like this:

doc = doc_ref.where(u'field',u'==',u'one').get()

But unfortunately nothing seems to work.... Is it possible?

1 Answers1

1

Maybe a composite query? eg.

doc_ref = (db.collection(u'mydocuments')
           .where(FieldPath.document_id(), u'==', dockey)
           .where(u'field', u'==', u'one'))
Hitobat
  • 2,847
  • 1
  • 16
  • 12
  • Thanks, tried it, but doesn't seem to work. Here someone suggests using '__name__' because there seems to be no direct equivalent in Python https://stackoverflow.com/questions/56676006/how-to-set-up-a-realtime-listener-for-document-title-within-firebase-collection Tried it too, be also without luck.. so I'm kinda stuck with this. unless someone else has another solution. – ByronSchuurman Nov 15 '21 at 17:46