
Hey, trying to create an AppUser
document and it's giving me an error saying $id is not allowed for creating new documents, try update instead
, do I have to create the document then update it with the wanted $id? I just want the AppUser to have the same ID as the auth user ID

Set it as the document ID when creating

Can you share the createDocument
code

Yeah, I think it's because you have id in your user object. It should be passed in the documentId argument of the createDocument method instead

Future<AppUser> getUserData(String uid) async {
try {
final appUserDocument = await db.getDocument(
databaseId: AppwriteConstants.databaseId,
collectionId: AppwriteConstants.usersCollection,
documentId: uid,
);
return AppUser.fromMap(appUserDocument.toMap());
} on AppwriteException {
final AppUser appUser = AppUser(
$id: user!.$id,
email: user!.email,
name: user?.name,
);
final appUserDocument = await db.createDocument(
databaseId: AppwriteConstants.databaseId,
collectionId: AppwriteConstants.usersCollection,
documentId: appUser.$id!,
data: appUser.toMap(),
);
return AppUser.fromMap(appUserDocument.toMap());
}
}
sorry should've shared it right away

Change it to this
Future<AppUser> getUserData(String uid) async {
try {
final appUserDocument = await db.getDocument(
databaseId: AppwriteConstants.databaseId,
collectionId: AppwriteConstants.usersCollection,
documentId: uid,
);
return AppUser.fromMap(appUserDocument.toMap());
} on AppwriteException {
final AppUser appUser = AppUser(
email: user!.email,
name: user?.name,
);
final appUserDocument = await db.createDocument(
databaseId: AppwriteConstants.databaseId,
collectionId: AppwriteConstants.usersCollection,
documentId: user.$id!,
data: appUser.toMap(),
);
return AppUser.fromMap(appUserDocument.toMap());
}
}

This way you would set the documentId
as the user ID
And, it will be at appUserDocument.$id

OH

I get it

$id was in the AppUser, thank you!!

[SOLVED] Unable to create document with $id?
Recommended threads
- Flutter OAuth2 Google does not return to...
When the flow starts, the browser opens, I select an account, and it keeps showing: """ Page not found The page you're looking for doesn't exist. `general_rout...
- JSON and Object Support in Collection do...
I am working with Next.Js and Appwrite Cloud, I am relatively New to Appwrite but i have noticed there is no direct support of JSON and Object support in attrib...
- list() is very slow; eventually shows no...
When I use the web browser to view the collections in my database, the documents they contain are normally displayed within a few seconds. For a few days now, h...
