Firestore database document 'startsWith' query

2,017 views
Skip to first unread message

Bishwajyoti Roy

unread,
Oct 4, 2017, 6:26:07 PM10/4/17
to Firebase Google Group
Is it possible to query on a firestore database collection to show documents that start with a specific string?

Michael Lehenbauer

unread,
Oct 5, 2017, 1:10:32 PM10/5/17
to Firebase Google Group
Hi Bishwajyoti,

You can essentially do this with a carefully-crafted range query...  E.g. to find documents with ID's that begin with 'foo', I believe you could do:

      collection
        .where(firebase.firestore.FieldPath.documentId(), '>=', 'foo')
        .where(firebase.firestore.FieldPath.documentId(), '<', 'fop')
        .get()
        .then(querySnapshot => { ... });

Hope this helps,
-Michael


On Wed, Oct 4, 2017 at 1:31 PM, Bishwajyoti Roy <bishwaj...@gmail.com> wrote:
Is it possible to query on a firestore database collection to show documents that start with a specific string?

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/6066fc41-f485-429f-9aca-972b765265d8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages