'Firebase Firestore REST Request - Query and Filter

I have a firestore database on a firebase project. I want to make rest request for filtering or querying data with postman. I'm using "https://firestore.googleapis.com/v1/projects//databases/(default)/documents/" to get the data in a known path in my database. Here is a sample of my database structure:

  • users > xxxxx > messages > yyyyy> "sent":"true"

where "users" and "messages" are collections, "xxxxx" and "yyyyy"are autogenerated document ids (xxxxx is autogenerated user id)

What I want to do is to find the "xxxxx"s (users) which have >"sent":"true"< data.

I get success if I know the "xxxxx" and "yyyyy" but I don't know them because they are autogenerated and different from each other in my database and don't know how to do it.



Solution 1:[1]

I am unable to get this to work for some reason. I have a Collection called dzs which has some documents with auto generated id's.

I want to query and find a document with a specific email address. When I try this in Postman, it returns (Error 400 Bad request)

"structuredQuery": {
    "from": [{
        "collectionId": "dzs",
        "allDescendants": true
    }],

    "where": {
        "fieldFilter": {
            "field": {
                "fieldPath": "email"
            },
            "op": "EQUAL",
            "value": {
                "stringValue": "[email protected]",
            }
        }
    }
}

Solution 2:[2]

Add the parent collection/document path to the URL:

var URL = "https://firestore.googleapis.com/v1/projects/<your-project-id>/databases/(default)/documents/users/xxxxx:runQuery";

Then make the collectionId "messages" and allDescendents false:

"structuredQuery": {
    "from": [{
        "collectionId": "messages",
        "allDescendants": false
    }],

    "where": {
        "fieldFilter": {
            "field": {
                "fieldPath": "sent"
            },
            "op": "EQUAL",
            "value": {
                "stringValue": "true",
            }
        }
    }
}

Source

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Peter Csala