How to update a firebase document

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:

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

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.

1 Like

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?

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.

1 Like

That works GREAT :slight_smile:

Thank you!