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
- Different Environments
Hello, good afternoon! I'm starting to use Appwrite and I have a question: how can I configure three different environments (such as development, staging and pr...
- Implement Auth using PRN no. and Passwor...
can i use appwrite databases as a auth provider as the built in auth only accepts email-password session but my project requires it to be a prn number. (college...
- Creating A User Account
I have a simple form component that is expected to create a new user using the the ###firstName, ###lastName, ###username, and ###password from a react-hook-for...