Remove item from database

Hi,
my collection holding information about users followers including 2 fields: userID and followerID.
when a user unfollow other user i want to delete the right row from the collection
how can i do this because i see you can delete from collection by one field but in my case the same userID can appear more than once(have more than one follower)
thank you!

If the userID and followerID are shown in multiple rows in your dataset then obviously you are better to not just simply use them as you won’t be sure of which one you are deleting if something was to go wrong with code on the page etc.

You would therefore have to look at a different way of querying your code then to maybe look for the users profile name that is being viewed and once you have found that, to then delete the followersID and userID from that row only.

https://www.wix.com/corvid/reference/wix-data.WixDataQuery.html

It depends on how your collection is structured.
If the follower is a reference, a multi-reference, a string of a single id or an array of followers

they will be shown in multiple rows but in the same row only once

its a string of a single id

Nuphar,
If you want to only delete the value of the second column, you can do something like:

wixData.query("CollectionName")
.eq("userID", "dasdasf-dsfsdfgd-sdfgfh")
.eq("followerID", "sdasd@asdfs.com")
.find()
.then(r => {
    let item = r.items[0];
    delete item.followerID;
    return item;
})
.then(item => {
    return wixData.update("CollectionName", item);
})
.then(() => {
    console.log("done");
})
.catch(err => {
    console.log(err);
})

@jonatandor35 thank you friend!

You’re welcome :slight_smile: