storing 2 objects into one

hello, i wanted to know how i could make my data be stored in one object in mongodb, since im using 2 different collectors (for buttons which shows a modal, and a string select menu) and i have to make a new object in mongodb for each of the data stored so how can i save them both in one object collector: https://srcb.in/YSOKZldr9C collector2:
collector2.on("collect", async (interaction) => {
if (interaction.customId === "select") {
try {
const selectedGames = interaction.values;

const Post = require("../schemas/postSchema");

for (const selectedGame of selectedGames) {
const newPost = new Post({
userId: interaction.member.id,
title: "Untitled Post",
description: "No description provided",
serverInvite: "Nothing provided",
serverJoinCode: "Nothing provided",
genre: "No Genre",
game: selectedGame,
id: generateId(),
time: Date.now(),
});

const savedPost = await newPost.save();
console.log("Post saved successfully:", savedPost);
}
interaction.reply("Selected games saved successfully.");
} catch (error) {
console.error("Error saving selected games:", error);
interaction.reply(
"An error occurred while saving the selected games."
);
}
}
});
collector2.on("collect", async (interaction) => {
if (interaction.customId === "select") {
try {
const selectedGames = interaction.values;

const Post = require("../schemas/postSchema");

for (const selectedGame of selectedGames) {
const newPost = new Post({
userId: interaction.member.id,
title: "Untitled Post",
description: "No description provided",
serverInvite: "Nothing provided",
serverJoinCode: "Nothing provided",
genre: "No Genre",
game: selectedGame,
id: generateId(),
time: Date.now(),
});

const savedPost = await newPost.save();
console.log("Post saved successfully:", savedPost);
}
interaction.reply("Selected games saved successfully.");
} catch (error) {
console.error("Error saving selected games:", error);
interaction.reply(
"An error occurred while saving the selected games."
);
}
}
});
1 Reply
d.js toolkit
d.js toolkit2mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!