I am attempting to create 12 documents in my games collection I am successfully able to create 5 and then there is a server error on 6 it will create 5 more and a server erron on 12.
Is there a way to make this create all 12 games?
this is the terminal output Game 1 created successfully. Game 2 created successfully. Game 3 created successfully. Game 4 created successfully. Game 5 created successfully. Error creating game 6: AppwriteException: Server Error
119 | if (gameData) { 120 | try {
121 | await databases.createDocument( | ^ 122 | process.env.NEXT_PUBLIC_APPWRITE_DATABASE!, 123 | process.env.NEXT_PUBLIC_APPWRITE_COLLECTION_LEAGUE_GAMES!, 124 | ID.unique(), { code: 500, type: 'general_unknown', response: [Object] } Game 7 created successfully. Game 8 created successfully. Game 9 created successfully. Game 10 created successfully. Game 11 created successfully. Error creating game 12: AppwriteException: Server Error
and this is the code we are using to process the createDocument
for (let gameNumber = 1; gameNumber <= 12; gameNumber++) {
const gameData = createGameData(
gameNumber,
newMatchup.$id,
team1Players,
team2Players
);
if (gameData) {
try {
await databases.createDocument(
process.env.NEXT_PUBLIC_APPWRITE_DATABASE!,
process.env.NEXT_PUBLIC_APPWRITE_COLLECTION_LEAGUE_GAMES!,
ID.unique(),
gameData
);
console.log(Game ${gameNumber} created successfully.);
} catch (error) {
console.error(Error creating game ${gameNumber}:, error);
// Handle the error, perhaps skip this game or try again later
}
}
}
return { success: true, matchup: newMatchup };
} catch (error) { console.error("Error creating league matchup or games:", error); return { error: "Failed to create matchup or games. Please try again.", }; } }
// Helper function to create game data based on game number function createGameData( gameNumber: number, matchupId: string, team1Players: string[], team2Players: string[] ) { const gameStructure = { 1: { team1: [0, 2], team2: [0, 2] }, 2: { team1: [1, 3], team2: [1, 3] }, 3: { team1: [0, 3], team2: [0, 3] }, 4: { team1: [1, 2], team2: [1, 2] }, 5: { team1: [0, 1], team2: [2, 3] }, 6: { team1: [2, 3], team2: [0, 1] }, 7: { team1: [0, 2], team2: [1, 3] }, 8: { team1: [1, 3], team2: [0, 2] }, 9: { team1: [0, 3], team2: [1, 2] }, 10: { team1: [1, 2], team2: [0, 3] }, 11: { team1: [0, 1], team2: [0, 1] }, 12: { team1: [2, 3], team2: [2, 3] }, };
const { team1, team2 } = gameStructure[gameNumber]; return { matchupId: matchupId, team1: [team1Players[team1[0]], team1Players[team1[1]]], team2: [team2Players[team2[0]], team2Players[team2[1]]], }; }
Recommended threads
- Project Inactivity Clarification
I'm on appwrite free plan with my account (om.thakkar@ivcventure.com). Even though throughout the week we use the project atleast once to upload dynamic content...
- Retrieving Data From Backups
Hiya, I have a user requesting for data they accidentally deleted. I don't have document history built into my app. Is there a way to extract data from the auto...
- [ENHANCEMENT] Use the custom Next.js dep...
Deployment adapters on Next.js are now stable! This means that we don't have to stick to the limitations of sniffing out build outputs and manually moving or mo...