Rank 1: Thread
PS: tried to create docs without the relational stuff and the issue still persists..
Votes
0
Replies
24
Participants
Unknown
Messages
25
Rank 1: Thread
PS: tried to create docs without the relational stuff and the issue still persists..
Rank 1: Thread
I am trying to create multiple docs at the same time
Like one by one going over the inputs of the users
Rank 1: Thread
something like :
for coreData in userUploads{ const coreDoc = await databases.createDocument( DATABASE_ID, CORE_COLLECTION_ID, ID.unique(), coreData );}Rank 1: Thread
and idk why same loop is working for all other collections but when I try to upload in this specific core collection
Rank 1: Thread
then only the 1st doc gets generated while all the rest get issues of "document with requested ID already exists"
Rank 1: Thread
and the doc that actually exists in the db is with some completely random ID like : 67e95fe700060d076680
and if i clear the db and run again
I again get completely unique id like 67e960dc000b6b5b40a2
Rank 1: Thread
import { Databases, ID, Query } from 'node-appwrite'; const DATABASE_ID = "sample_db";const CORE_COLLECTION = "users_core";const SOCIAL_COLLECTION = "users_social";const PREFS_COLLECTION = "users_preferences";
// Sample data structureconst sampleUser = { name: "Alex Smith", // Social links social: { github: "github.com/alex", }, // Preferences preferences: { language: "en" }};
async function createUserWithRelations() { try { const userUUID = ID.unique(); // Create social links document const socialDoc = await databases.createDocument( DATABASE_ID, SOCIAL_COLLECTION, ID.unique(), { userUUID: userUUID, github: sampleUser.social.github, } ); // Create preferences document const prefsDoc = await databases.createDocument( DATABASE_ID, PREFS_COLLECTION, ID.unique(), { userUUID: userUUID, language: sampleUser.preferences.language } ); // Create core user document with references const coreDoc = await databases.createDocument( // <--- Error here DATABASE_ID, CORE_COLLECTION, ID.unique(), { userUUID: userUUID, name: sampleUser.name, socialId: socialDoc.$id, preferencesId: prefsDoc.$id } ); return { core: coreDoc, social: socialDoc, preferences: prefsDoc }; } catch (error) { console.error("Error creating user:", error); throw error; }} Rank 1: Thread
this is a pseudo code of what I'm trying to do /how im working with my relational db
Rank 1: Thread
also tried the nested method , something like this :
async function createDocument() { try { // Single document creation with nested data const doc = await databases.createDocument( DATABASE_ID, MAIN_COLLECTION, ID.unique(), { name: sampleData.name, email: sampleData.email, // Directly embedding related data as nested objects socialMedia: sampleData.social, preferences: sampleData.preferences } ); return doc; } catch (error) { console.error("Error creating document:", error); throw error; }}and even this is not working
Rank 1: Thread
response: '{"message":"Document with the requested ID already exists. Try again with a different ID or use ID.unique() to generate a unique ID.","code":409,"type":"document_already_exists","version":"1.6.2"}'
Do you have a unique index on any of those attributes?
Rank 1: Thread
initially I was not having a unique index as I thought the appwrite $id does a unique index automatically
but now I just added a unique index as the UUID of the user
and still the issue persists
So you didn't have any unique indexes before?
Does this collection have any relationship attributes? do you have unique indexes on any of your collections?
Btw, relationship attributes are experimental and should be used with caution as they can lead to performance problems
Rank 1: Thread
yes
Rank 1: Thread
I have a unique Index called user UUID
in all of the 3 collections
There were two questions
Rank 1: Thread
just a sec answering all
Rank 1: Thread
Perhaps a new document is trying to be created instead of linking the existing document which is why you see the duplicate error
Can you share your exact code?
Rank 1: Thread
also really sorry for my dumbness , its my first time working with appwrite db 😅
Rank 1: Thread
thats honestly what I also thought
but then I tried to use nexted way of creating the document
and still facing the same issue
Rank 1: Thread
can I just send it over on dms?
Rank 1: Thread
its almost 80% identical , only the variable names are different