Promise.all in the code below keeps failing and giving me a "fetch failed" error and I can't for the life of me figure out why. Also I ran this function a bunch in a dev environment several months ago no problem. Now I am running it on Appwrite Cloud. I can list documents no problem, I have another function that updates documents no problem but this function where I try to create and update in bulk is giving me fits.
const playerIndex = await buildPlayerIndex(database);
const updateOperations = [];
const createOperations = [];
for (const playerId in players) {
const player = players[playerId];
if (player.position === 'DEF' || player.first_name === 'Duplicate') continue;
const document = {
'playerId': playerId,
'name': player.full_name,
'first_name': player.first_name,
'last_name': player.last_name,
'position': player.position,
'team': player.team,
'college': player.college,
'number': player.number,
'age': player.age,
'fantasy_positions': player.fantasy_positions,
};
if (playerIndex.has(playerId)) {
const documentId = playerIndex.get(playerId);
updateOperations.push(database.updateDocument(DATABASE_ID, COLLECTION_ID, documentId, document));
} else {
createOperations.push(database.createDocument(DATABASE_ID, COLLECTION_ID, ID.unique(), document));
}
}
log(`Number of update operations: ${updateOperations.length}`);
log(`Number of create operations: ${createOperations.length}`);
await Promise.all([...updateOperations, ...createOperations])
.catch(e => error(`Promise.all failed: ${e.message}`));
}```
Recommended threads
- Relation Question
How do I create a relation from table y to an others x.$id. in my example I have a users table where I use Appwrites unique User IDs and I want other tables fo...
- Unknown attribute type: varchar / text
Since the `string` type is deprecated I tried using `varchar` and `text` in some newer tables, but when running `appwrite pull tables && appwrite types ./src/li...
- I'm experiencing a critical bug on Appwr...
Hey <@870607367597850624> team / support 👋 I'm experiencing a critical bug on Appwrite Cloud that's blocking my production Flutter app. I've already filed GitH...