How to update product metafields based on product tags

I have a Shopify store where I where I’ve two products meta fields

  1. product.metafields.Collection.collection

  2. product.metafields.Product.product

But my store is huge with a lot of products

So what I want to achieve is to make the product tag that starts with Product. (e.g Product_product test) to be added to the first metafield on the product page

Similarly, the product tag that starts Collection_ (e.g Collection_Collection test) to be added to the 2nd metafield on product page

Any suggestions? Thanks in advance.

Have you tried using if conditions to display the metafield? Eg. If product_tag is not empty then display metafield ?