Delete item from array Field

default discord avatar
LuisLopezlg
last month
1

Hi, is there a way to delete/update/push an item from an array with payload? the item is a relationship field


I couldn't find something like that in the docs.


I was reading other questions here in discord and i ended up doing the next:



I got the "guildModel" from payload and then I just worked with mongoose to remove a specific item from the array.



export const deleteBusReferencesFromGuild = async ({ guildId, busId, req }) => { const { payload } = req; const guildModel = payload.collections["guilds"].Model; const data = { buses: { busId } }; try { const res = await guildModel.updateOne( { _id: guildId }, //@ts-ignore { $pull: data }, ); return res; } catch (error) { console.log({ error }); } };
  • discord user avatar
    Jarrod
    Payload Team
    last month

    @LuisLopezlg currently, you need to push the entire array in its updated format 👍

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.