How use removeReference..... Help

Hello,
I’m looking for someone to help me.
For some time to understand how to delete from a dataset with a reference field all the references of this table referring to an id of the source table.

I’ll explain:

I have this table called “DataSetEventoLightroom” where there is a reference field to a main table


I would like to be able to delete all the items that refer to the same reference of the main folder:

this is what I tried to do. I used removeReference because remove can not remove more than one item at a time.

I know the id of the main table so I find the object all the items in the table referenced by the reference id

function countRowLightTable() {
    wixData.query("DataSetEventoLightroom")
    .eq('DB_EventoCodice', idEvento)
    .find() 
    .then( (results) => {
        itemsLightTrovate = results.items;
    });
}

Now I try to use removeReference to delete all references from the table

export function button17_click(event) {
    wixData.removeReference('DataSetEventoLightroom', 'DB_EventoCodice', 'idEvento', 'itemsLightTrovate')
    .then(() => {
        console.log('Erase item');
    });
}

where is it:

  • DataSetEventoLightroom - is the name of the table with references

  • DB_EventoCodice - is the column where the reference to the main table is saved

  • idEvent - is the id of the main table saved in the reference column

  • itemsLightTrovate - are all the items found by the query in the table with the same reference

I hope I have been clear and that someone can help me.

Thank you all

I have done other tests and I can not understand how I can use removeReference.

I wrote the removal of the items with an array:

function countRowLightTable() {
    wixData.query("DataSetEventoLightroom")
    .eq('DB_EventoCodice', idEvento)
    .find() 
    .then( (results) => {
        itemsLightTrovate = results.items;
        VariantiTrovateLightroom = results.totalCount;
    });
}

export function button17_click(event) {
let i=0;
 while(i<VariantiTrovateLightroom) {     
    wixData.remove("DataSetEventoLightroom", itemsLightTrovate[i]._id)
    i++;
 }
 console.log('Delete Item');
}

I hope someone can answer me to understand if it is possible to use removeReference to do this, and possibly how to do it, because I can not manage it.

Thank you