简体   繁体   中英

How to delete multiple fields from multiple documents in firestore through the REST API?

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM