0

Working on a react native app and having issues with the Appwrite database.

here is the error:

ERROR Error seeding data: [AppwriteException: Invalid document structure: Missing required attribute "image"]

import { ID } from "appwrite";
import { databases, config } from "./appwrite";
import { agentImages, galleryImages, propertiesImages, reviewImages } from "./data";

const COLLECTIONS = {
  AGENT: config.agentsCollectionId,
  REVIEWS: config.reviewsCollectionId,
  GALLERY: config.galleriesCollectionId,
  PROPERTY: config.propertiesCollectionId,
};

const propertyTypes = [
  "House",
  "Townhome",
  "Condo",
  "Duplexe",
  "Studio",
  "Villa",
  "Apartment",
  "Other",
];

const facilities = [
  "Laundry",
  "Car-parking",
  "Sports-center",
  "Cutlery",
  "Gym",
  "Swimming-pool",
  "Wifi",
  "Pet-center",
];

I tried to check the database and I used AI to assist me with the issues that I am having problems with but it was not able to resolve the issue.[database][error while app is running]

What I tried:

  • I tried to change the image in the database to a string or a url - neither worked when seeding the database.

  • I also tried to create the images and the properties myself so that I can check if the loop runs or not and diagnose where the error might occur within the data and the code for seeding the data.

19
  • function getRandomSubset<T>( array: T[], minItems: number, maxItems: number ): T[] { if (minItems > maxItems) { throw new Error("minItems cannot be greater than maxItems"); } if (minItems < 0 || maxItems > array.length) { throw new Error( "minItems or maxItems are out of valid range for the array" ); } Commented Oct 4 at 22:42
  • ``` // Generate a random size for the subset within the range [minItems, maxItems] const subsetSize = Math.floor(Math.random() * (maxItems - minItems + 1)) + minItems; // Create a copy of the array to avoid modifying the original const arrayCopy = [...array]; ``` Commented Oct 4 at 22:45
  • ``` // Shuffle the array copy using Fisher-Yates algorithm for (let i = arrayCopy.length - 1; i > 0; i--) { const randomIndex = Math.floor(Math.random() * (i + 1)); [arrayCopy[i], arrayCopy[randomIndex]] = [ arrayCopy[randomIndex], arrayCopy[i], ]; } // Return the first subsetSize elements of the shuffled array return arrayCopy.slice(0, subsetSize); } ``` Commented Oct 4 at 22:45
  • ``` async function seed() { try { // Clear existing data from all collections for (const key in COLLECTIONS) { const collectionId = COLLECTIONS[key as keyof typeof COLLECTIONS]; const documents = await databases.listDocuments( config.databaseId!, collectionId! ); for (const doc of documents.documents) { await databases.deleteDocument( config.databaseId!, collectionId!, doc.$id ); } } console.log("Cleared all existing data."); } ``` Commented Oct 4 at 22:46
  • 1
    What's going on with these comments? Are you trying to edit the question? Commented Oct 4 at 23:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.