
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
- Is it possible to getRow with all relati...
With the new Opt-In relationship loading, is it possible to query getRow to get all attributes and relationships and possibly even cascading relationships? I tr...
- TableDB.getRow() response does not conta...
This is for Web/React sdk 20.0.0 The row was created via `TableDB.createRow(...)` and I can see it in the console with the relationships correctly set. In the c...
- Permissions for bulk operation
Hi team, I have a question: “In the databases.createDocuments bulk API, can I set document-level permissions? If yes, how exactly should I include the permissio...
