Firestore document updates adding unnecessary metadata to documents?

Hi folks - brand new to retool and excited about the capabilities already. I'm testing some capabilities with a dummy project in Firestore.

Following the guide to create a table with editable fields for a specific collection. My collection is quite simple:

things/

  • Created At Timestamp
  • name
  • user id

When I edit the name field using steps in the guide to update a single recordin the table, it appears to be writing back the updated name (nice!) but it's also adding in the following to the document (when viewing in Firebase Console):

  • a map called __metadata that has an array called segments
    • on index [0] it has the collection name: things
    • on index [1] it repeats the document's id
  • a field called _id (duplicates the documents id)

Curiuous what these fields are and how I could keep my documents cleaner by not writing the back to the document each time I edit a single field.

Thanks for any help for this new retool user!

Friendly bump. Curious if anyone might have a lead on what’s happening here?

Hi @json2001! Welcome to the community! :sunglasses:

Two of Retool's Firestore queries will include this metadata, Query Firestore and Query Collection Group. Are you referencing the queried collection object in your update statement? You should be able to see this in the model browser:

image

So if you're referencing this in your update statement, the metadata field will also be included:

If you have no use for the metadata, you can trim this from the object right when the data is brought into Retool by using a transformer on the query:

You could also exclude this when sending your updated item back to Firestore:

1 Like

Thank you very much for the detailed reply. Appologies, but I may need a little hand holding here. Both of your solutions make sense, but I'm struggling with how exactly to implement.

Here's where I have in my updateRecord query (this is using an editable table field where I have a single field called "name" that I want to be editable. (This did not seem to work).

Another question/idea is perhaps I could use an "Update" method for each object instead of replacing the entire object? That way I only update the single "name" field? Is that also possible?

Thank you again for the detailed and helpful response and warm welcome!

I found this other guide in the forums that helped me out: How to use the editable table feature with Firebase

1 Like

@json2001 were you able to figure it out? RE: the transformer, you’ll want to create a separate standalone transformer (more on this difference here), and then reference {{ transformer.value}} in your Firestore insert query.

Thanks for the follow up @justin!

I was able to get this working how I expected by following the link to the guide in forums I posted previously. So I didn’t get into the transforms this round , rather had the JS query omit those fields from the set.

@json2001 gotcha, glad you figured it out :slight_smile: