1
votes

I'm trying to execute the following query with Firestore REST API, and I find the documentation to be very limited on more complex queries. Basically I want to use WHERE IN query.

const allowedIds = ['xxxx', 'zzzz', 'yyyy'];
let myQuery = firebase.firestore().collection('myCollection').where(firebase.firestore.FieldPath.documentId(), 'in', allowedIds);

This one works perfectly, but now I want to convert it around. Here is what I've tried so far:

const allowedIds = ['xxxx', 'zzzz', 'yyyy'];

            'structuredQuery': {
            'from': [{
                'collectionId': 'myCollection',
            }],
            'where': {
                'fieldFilter': {
                    'field': {
                        'fieldPath': firebase.firestore.FieldPath.documentId(),
                    },
                    'op': 'IN',
                    'arrayValue': {
                        'values': [
                            {
                                'stringValue': 'xxxx',
                            },
                            {
                                'stringValue': 'zzzz',
                            },
                        ],
                    },
                },
            },
        },

It seems that the problem is in using firebase.firestore.FieldPath.documentId() to reference a document ID, but is there another way to achieve that? The error message I currently get:

"Invalid value at 'structured_query.where.field_filter.field' (field_path), Starting an object on a scalar field Invalid JSON payload received. Unknown name "arrayValue" at 'structured_query.where.field_filter': Cannot find field."

My data structure: I have vehicles and users collections. Users have a field called vehicles which is an array of strings(vehicles collection document id-s). So I would like to query vehicles collection WHERE IN the user.vehicles

1
Could you provide an example of your data structure, to try and replicate the query on my side? - Emmanuel
@Emmanuel I have 'vehicles' and 'users' collections. Users have a field called 'vehicles' which is an array of strings(vehicles collection document id-s). So I would like to query vehicles collection WHERE IN the user.vehicles - raouaoul
You should update your question with an example of those collections, that could help to try and replicate the issue and provide a good answer. - Jane Jetson

1 Answers

0
votes

Try replacing firebase.firestore.FieldPath.documentId() by "__name__".