Skip to content

Instantly share code, notes, and snippets.

@mannyyang
Last active August 23, 2021 19:51
Show Gist options
  • Select an option

  • Save mannyyang/2091d7cf453966ea63c1739ab32a5872 to your computer and use it in GitHub Desktop.

Select an option

Save mannyyang/2091d7cf453966ea63c1739ab32a5872 to your computer and use it in GitHub Desktop.
/**
* 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