0
votes

I need to update certain Firestore documents within transactions.

firestore.projects.databases.documents.beginTransaction fails when creating a readWrite transaction, but succeeds for a readOnly transaction.

I've ensured that the database is in test mode, with all reads and writes open

service cloud.firestore {
    match /databases/{database}/documents {
        match /{document=**} {
        allow read, write: if true;
        }
    }
}

(this fails)

https://firestore.googleapis.com/v1beta1/projects/foo-bar-12345/databases/(default)/documents

    { 
        "options": {
            "readWrite": {}
        }
    }

error response:

    {
        "error": {
            "code": 403,
            "message": "Missing or insufficient permissions.",
            "status": "PERMISSION_DENIED"
        }
    }

(this succeeds) - changing options to readOnly, returns a tranasaction

https://firestore.googleapis.com/v1beta1/projects/foo-bar-12345/databases/(default)/documents

    { 
        "options": {
            "readOnly": {}
        }
    }

Successful response:

    {
        "transaction": "EcMecxy5IXKoIlkAIx+ixOCJ/NT6gvpbaEwWk/5YkOxVxSeMWpOdG4H2nZGK3Y0Pmcj+lbvk6sAlw68UpFgjd8puTpyS2Vwm2X6mw2SKKKKK9OakXxkGgi+8o4vx70Qd4YQaGg=="
    }
1
How are you authenticating your requests, Firebase Auth or Google OAuth? The security rules should only affect your request if you use Firebase Auth, cloud.google.com/firestore/docs/…. - Juan Lara
Thx Juan. The database is in test mode, completely open for reads and writes, so I'm not authenticating at all. I can successfully create, read, update or delete documents. The only thing I can't seem to do is create a readWrite transaction - gav

1 Answers

1
votes

The beginTransaction REST API method does not support un-authenticated requests for readWrite transactions.

To atomically commit multiple un-authenticated writes, you can use the commit method.