0
votes

I am trying to query all Documents where DocumentID begins with my string. My research tells me it's possible for field values by using '<=' in where(), but I have not found anything online that tells how to do this on Document ID fields.

I am doing this because my table contains Geohashes as DocumentIDs (high precision) with data, and I would like to get those documents on bases of low precision Geohash.

I also found this as a potential solution:

docs = mycolRef.where(firebase.firestore.FieldPath.documentId(), '>', somestring).stream();

However, this gives the error: "NameError: name 'firebase' is not defined"

I am importing firestore through google.cloud as mentioned in this guide: (https://cloud.google.com/firestore/docs/quickstart-servers)

from firebase import firestore, or import firebase resulted in errors.

1
Try docs = mycolRef.where(Firestore.FieldPath.documentId(), '>', somestring).stream(); where you have previously coded ... const Firestore = require('@google-cloud/firestore');Kolban
Thank you for a quick response. I am using Python to run Firestore operations, and const Firestore = require('@google-cloud/firestore'); doesn't work in Python. I tried reading up on this, but found very limited documentation on node.js (cloud.google.com/nodejs/docs/reference/firestore/0.8.x/…) Could you explain some more, or provide equivalent for Python? (or where I could find it?). Thank you,sudcha

1 Answers

2
votes

How to query Documents where DocumentID begins with a substring?

There is currently no way you can achieve that.

I have not found anything online that tells how to do this on Document ID fields.

You haven't found anything because such a query does not exist.

My research tells me it's possible for field values by using '<=' in where()

Yes, that's the only option you have now. So add all those Geohashes which are now documents ids as values of a new (geohash) property within your document.

I also found this as a potential solution:

docs = mycolRef.where(firebase.firestore.FieldPath.documentId(), '>', somestring).stream();

Unfortunately, you cannot do that, hence that error.

One more thing to note is that in Firestore, it is not possible to change the document ids once it exists. All that data is immutable. What you can do instead is to read all the documents, change the document id and then put it all back.