Skip to content

Appwrite indexes creation solution #3

Description

in src/models/server/question.collection.ts, we can add a delay to ensure attributes are fully propagated before indexing;

await Promise.all([
    databases.createStringAttribute(db, questionCollection, "title", 100, true),
    databases.createStringAttribute(db, questionCollection, "content", 10000, true),
    databases.createStringAttribute(db, questionCollection, "authorId", 50, true),
    databases.createStringAttribute(db, questionCollection, "tags", 50, true, undefined, true),
    databases.createStringAttribute(db, questionCollection, "attachmentId", 50, false),
]);

console.log("Attributes created successfully");

// Adding a delay to ensure attributes are fully available before indexing
await new Promise(resolve => setTimeout(resolve, 2000));

await Promise.all([
    databases.createIndex(db, questionCollection, "title", IndexType.Fulltext, ["title"], ["asc"]),
    databases.createIndex(db, questionCollection, "content", IndexType.Fulltext, ["content"], ["asc"]),
]);

console.log("Indexes created successfully");

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions