grahamearley / FirestoreGoogleAppsScript

A Google Apps Script library for accessing Google Cloud Firestore.
http://grahamearley.website/blog/2017/10/18/firestore-in-google-apps-script.html
MIT License
648 stars 109 forks source link

Query with IN operator? #79

Closed socraticat closed 4 years ago

socraticat commented 4 years ago

Hi, thank you for this library as I've been using this for a small Firestore-Google Sheets project. I have a rather large collection of documents and I need to retrieve 10-20 at a time using the IN operator.

I'm not sure if I missed it in the docs but this doesn't seem to be supported yet. Is there an operator I can use to query something like: where field IN [1,2,3,4,5]?

LaughDonor commented 4 years ago

I apologize the documentation isn't clearly updated with this, but try out:

var results = db.query('path/to/collection').where('fieldName', 'contains', true).offset(0).limit(20).execute()

This will get first 20 documents with array fields named "fieldName" that contain a JS true value.

Is this what you're looking for?

socraticat commented 4 years ago

Sorry, I should give a clearer explanation. I have a collection in 'path/to/collection' in which each item has a string ID field, let's say test1, test2, etc. There can be potentially hundreds of these items with unique IDs but I would like to query X at a time by providing an array of IDs like so (in SQL terms):

SELECT * FROM collection WHERE ID IN ("test1", "test2", "test3", "test4")

Also works if I can just query by the actual Document ID (or UID), I've made redundancies in case only one of them works.

LaughDonor commented 4 years ago

I see what you're getting at. This was missing, and I've released v24 that allows this.

Thanks for bringing this up!