Back

Issues with storage/database adding function

  • 0
  • Databases
  • Storage
Kimhi
26 Jul, 2024, 23:03

Hi, Im working on a register form where I need to upload a document to a storage as well as creating a new document in my database. For some reason I get an exception saying 'Invalid document structure: Missing required attribute "userid"' , My confusion is that I dont need to send any userId in databases.createDocument or storage.createFile so Im confused where am I missing this attribute

TypeScript
  identificationDocument,
  ...patient
}: RegisterUserParams) => {
  try {
    // Upload identification file to appwrite storage
    let file;
    if (identificationDocument) {
      const inputFile =
        identificationDocument &&
        InputFile.fromBuffer(
          identificationDocument?.get("blobFile") as Blob,
          identificationDocument?.get("fileName") as string
        );
      file = await storage.createFile(
        process.env.NEXT_PUBLIC_BUCKET_ID!,
        ID.unique(),
        inputFile
      );
      const newPatient = await databases.createDocument(
        process.env.NEXT_PUBLIC_DATABASE_ID!,
        process.env.NEXT_PUBLIC_PATIENT_COLLECTION_ID!,
        ID.unique(),
        {
          identificationDocumentId: file?.$id ? file.$id : null,
          identificationDocumentUrl: file?.$id
            ? `${process.env.NEXT_PUBLIC_ENDPOINT}/storage/buckets/${process.env.NEXT_PUBLIC_BUCKET_ID}/files/${file.$id}/view??project=${process.env.NEXT_PUBLIC_PROJECT_ID}`
            : null,
          ...patient,
        }
      );
      return parseStringify(newPatient);
    }
  } catch (error) {
    console.log(error);
  }
};```
TL;DR
Issue: Developer is encountering an exception 'Invalid document structure: Missing required attribute "userid"' while working on a register form for uploading a document to storage and creating a new document in the database. Solution: Make sure to include a valid 'userid' attribute in the createDocument function when creating a new document in the database.
Steven
26 Jul, 2024, 23:29

Can you share a screenshot of your patient collection's attributes?

You're following JS Mastery's "Build and Deploy a Patient Management System with Next.js" tutorial (https://www.youtube.com/watch?v=lEflo_sc82g) huh?

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more