0

So far I have been deleting fields of documents through the REST API with the appropriate PATCH method. The API request as constructed in Postman is as follows:

url: https://firestore.googleapis.com/v1/projects/{project name}/databases/(default)/documents/{collection name}/{document name}/?updateMask.fieldPaths={name of field for deletion}

body of request:

{
    "fields": {}
}

with the approriate authorization headers. However this method can delete a single field from a single document.

How can I construct the request so that I can delete multiple fields from multiple documents on one go?

Mario
  • 561
  • 3
  • 18
  • 2
    Have you tried [batched writes](https://firebase.google.com/docs/firestore/manage-data/transactions#batched-writes)? Here is similar [thread](https://stackoverflow.com/a/48175690/18265570) which might help you. and have a look at this [document](https://firebase.google.com/docs/firestore/reference/rest/v1/projects.databases.documents/batchWrite) too. – Roopa M Aug 11 '22 at 08:20

1 Answers1

1

You can try Batched writes to delete fields from multiple documents. A batched write is a set of write operations on one or more documents. You can use delete() class of batched writes to delete fields from multiple documents.

For more information you can refer this StackOverflow thread and this document

Update:

Currently the v1 API & v1beta1 API only allows deleting multiple fields in a single document. So, I’m afraid that you may have to call API multiple times. And I don’t think there any other API methods that will help to delete multiple documents. I believe batched writes REST resources would be the good workaround for this.

If you think that, it is a valid feature request you can raise request here

Roopa M
  • 2,171
  • 4
  • 12
  • Thanks again, however I am looking for a REST API solution, and the `delete` class I believe is part of the js client library implementation. The solution I am looking for contains the structure of the API call (url, body). Also the API methods linked to are for deleting documents and not fields of documents (one uses the `DELETE` api method, while the other, the `PATCH` method.) – Mario Aug 18 '22 at 18:54
  • 1
    @Mario I updated my answer. Can you have a look at my answer? – Roopa M Aug 19 '22 at 09:44
  • Thank you for looking into this matter, it seems the workaround with REST resources is the only option currently. – Mario Aug 19 '22 at 19:06