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 });
}
};
@LuisLopezlg currently, you need to push the entire array in its updated format 👍
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.