Arockiasamy
Arockiasamy

Reputation: 60

Multiple where condition with structured query of a Firestore query using the REST API

export const structuredQuery = {
    "from": [{
        "collectionId": "products",
        "allDescendants": false
    }],

    "where": {
        "fieldFilter": {
            "field": {
                "fieldPath": "name"
            },
            "op": "EQUAL",
            "value": {
                "stringValue": "test"
            }
        }
    }
};

above is the sample structured query which I have right now, here I need to add "category" as new condition (like name).

please any one help me on this.

Upvotes: 1

Views: 835

Answers (1)

Animal
Animal

Reputation: 386

You can use use a CompositeFilter as they give the option to query on more than one field. Just keep in mind that if you order the query it shall be on the first fiel of the filter.

export const structuredQuery = {
    "from": [{
        "collectionId": "products",
        "allDescendants": false
    }],

    "where": {
        "compositeFilter": {
            "op": "AND",
            "filters": [{
                "fieldFilter": {
                    "field": {
                        "fieldPath": "name"
                    },
                    "op": "EQUAL",
                    "value": {
                        "stringValue": "test"
                    }
                }
            }]
        }

    }
};

Upvotes: 6

Related Questions