0

The documentation for updating a document reference with Cloud Firestore shows how to update a single field: const res = await cityRef.update({capital: true});

(https://firebase.google.com/docs/firestore/manage-data/add-data)

What if I want to update multiple fields of the document from the body of a PUT request?

For example, if my request.body is

{
    name: "Chicago"
    capital: true
}

Is there someway to update the doc in a single call, such as cityRef.update(request.body}?

scientiffic
  • 9,045
  • 18
  • 76
  • 149

2 Answers2

2

You can either use:

cityRef.update({
    name: "Chicago"
    capital: true
})

or

cityRef.set({
    name: "Chicago"
    capital: true
}, { merge: true })
Francesco Colamonici
  • 1,147
  • 1
  • 10
  • 16
0

If you want to update multiple fields in a Firestore document, you need to format your request using field, value, field, value, field, value...

You can use the .update to achieve your goal. Something like:

[...] cityRef.update({
    "name", “Chicago”, // field, value
    "capital, "true" // field, value
})

should do the trick. You will need to add the details in the [...]

maniSidhu98
  • 527
  • 2
  • 9