Updating tags in a table

Hi there -

I've been using Retool for less than 24 hours, so sorry if this is a rookie error!

I am using the (new) Table element and have created a tags type column called "Teacher". The list of teachers is pulling from a query where the label is a friendly name, and the record ID is the value.

No records in the table are already tagged, so everything pulls up blank initially as expected. Once I tag the records, I created a trigger to update the corresponding records (MongoDB).

Issue is, I can't seem to figure out how to get the array of tag values out of the table and reference it in my query. All combinations of my attempt have resulted in "undefined". How do I reference the tags?

I hope my question is clear and I thank you in advance for any help!

Hello, welcome to community.
since your origin data of teacher column is empty, so what you get in table1.selectedRow.teacher is undefined.

The value Wajiha is a changed value save in table1.changesetArray, you should use this value in update statement.

Also pls notice that your column type of teacher is Tags instead of Tag, this will result to a array instead of string.

1 Like

Thank you so much for pointing out where to find the changed data. This leads to another point of confusion - how do I get this changed data into my MongoDB? Do I need to write a javascript function? Or is there a more straightforward way (please let there be!).

I have my table right now triggered to update on tag change, but I can change that to be a bulk 'save' update of all changed rows if one is better than the other as far as ease of implementation.

BTW, I did intend to use the 'tags' option as multiple teachers can be assigned to a particular record.

High level database structure:
Student Collection has an element called "teachers" which is an array of teacher ID's. The ID's correspond to a document in the Teacher Collection.

Random question - I can't seem to find how to put a placeholder text in the rows that do not have any tags. Something like "Select Tag". Right now, it is just a blank cell and you have to click around to trigger the drop down.

Welcome to Retool @Jessica_D!

You do (for now) have to write some JavaScript to update the records in your MongoDB, but it shouldn't be too much more complicated that what you've written so far.

I'm admittedly not super familiar with the MongoDB resource connector, but I believe the quickest implementation would be to use the bulkWrite action type, and write some JavaScript to transform the changesetArray into a set of updates for MongoDB to perform. Something on these lines maybe:

Note that the records in changesetArray will include the primary key of the row, along with any changed values. You can change this if you need to reference other values on the record in the Advanced Interaction section:

To fully set-up a bulk write-back flow, you'll want to connect the "Save" action of the Table to trigger the query:

To configure a placeholder look for the "Placeholder" Add-on in the column inspector:

Please let us know if you run into any other points of confusion as you finish building your first tool!

Thank you for such a thorough response!

I am early enough in the design/build that I just ended up doing away with MongoDB and trying out the Retool database instead. It is much easier to work with so thank you. I do have 'tag' working, but I wasn't able to get 'tags' (multiple teachers) to work as I wanted because I do not think Retool DB supports arrays just yet. Is this something that will be incorporated in the near future?

I have the placeholder configured as you suggested but still do not see it showing up when the tag column is null.

1 Like

Hi @Jessica_D array support for RetoolDB is a feature request that we're tracking -- hopefully we're able to ship it soon :slightly_smiling_face:

Can you provide an update on the missing placeholder bug? It seems other users have reported the same issue.

Hi @Jessica_D It looks like the Placeholder only shows if the value is undefined (not if the value is null)

Can you try {{currentSourceRow.teacher ? currentSourceRow.teacher : undefined}}?

That worked, thank you!