How to update a firebase document


#1

Hi there!

New to this (amazing!) tool, and trying to figure how to update an existing firebase document, rather than add a new one… Basically, I have a single document within a collection, and I want to change one field within it from the react app…

Is that possible to do?

Many thanks in advance for any help :slight_smile:


#2

If you are using Firebase and Firestore as your database, I suggest you read this guide. You’ll learn two important methods. set() and update(). Another thing to learn. Using { merge: true } you specify that the data should be merged into the existing document. https://cloud.google.com/firestore/docs/manage-data/add-data. One thing to consider. Learning React, Firebase/Firestore cloud, and React Studio you have to iterate over and over again to find the right way to do it. Some times is a small detail, such as missing 'comma, sometimes you’re not passing the props as it should.

Regards


#3

In the Studio if you access document via list (Details view or list item) then it knows to write code for update. Otherwise it’ll create a new document.


#4

aahhh, so if I pull the document into a list component editable field?

And then use a button to trigger ‘save data’ but it’ll know to update, not write a new one?


#5

I think it should work also directly from list item as well. Give it a test and check the generated code or test in localhost. Usually In the apps the edits happens in details view which is accessed from list.


#6

That works GREAT :slight_smile:

Thank you!