Last active
August 23, 2021 19:51
-
-
Save mannyyang/2091d7cf453966ea63c1739ab32a5872 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Update an existing document in a collection. | |
| */ | |
| export async function updateDocumentInCollection({ docID, title, published, modified }) { | |
| const accessToken = await getAccessToken() | |
| const response = await ( | |
| await fetch( | |
| 'https://firestore.googleapis.com/v1/projects/<PROJECTIDHERE>/databases/(default)/documents/<COLLECTIONNAME>/<DOCID>?updateMask.fieldPaths=title&updateMask.fieldPaths=published&updateMask.fieldPaths=modified', | |
| { | |
| method: 'POST', | |
| headers: { | |
| Authorization: 'Bearer ' + accessToken.access_token, | |
| }, | |
| body: { | |
| fields: { | |
| title: { stringValue: title }, | |
| published: { booleanValue: published }, | |
| modified: { timestampValue: modified } | |
| } | |
| } | |
| } | |
| ) | |
| ).json() | |
| return response | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment