Back

[SOLVED] Getting Invalid Query exception and it's not the 14.0.0 version problem.

  • 0
  • Databases
  • Web
  • Cloud
Gaxve
18 Apr, 2024, 10:58

Trying to navigate to a post I made, I get this error: Invalid query: {"method":"equal","attribute":"slug","values":["test-post"]} and I checked if the slugs are the same and they are. Not sure what the problem might be.

TypeScript
---
import { Query } from "appwrite";

import { databases } from "../../lib/appwrite";

import Layout from "../../layouts/Layout.astro";
import Container from "../../components/container.astro";

const { postSlug } = Astro.params;

const { documents } = await databases.listDocuments(
  import.meta.env.PUBLIC_DATABASE_ID,
  import.meta.env.PUBLIC_COLLECTION_ID,
  [Query.equal("slug", String(postSlug))]
);

if (!documents.length) {
  return Astro.redirect("/404");
}

const post = documents[0];
const publishedDate = new Date(post.$createdAt);
console.log("documents", documents);
---

<Layout title={`${post.title} - My Blog`}>
  <Container>
    <article class="prose mx-auto">
      <h1 class="text-4xl font-extrabold mb-6">{post.title}</h1>
      <p class="text-slate-500 mb-14">
        <time datetime={publishedDate.toISOString()}
          >Published {publishedDate.toLocaleDateString()}</time
        >
      </p>
      <Fragment set:html={post.content} />
    </article>
  </Container>
</Layout>

The code above is my [postSlug].astro

TL;DR
The developer was getting an Invalid Query exception, even though they thought it was not due to the 14.0.0 version. The issue was related to a syntax problem after downgrading to appwrite 13.0.2. The solution suggested was to delete the `node_modules/` folder and run `npm install` again.
ideclon
18 Apr, 2024, 11:00

You say it’s “not the 14.0.0 version problem”, but that is the Appwrite 1.5 Query syntax. What makes you say it’s not the SDK version?

Gaxve
18 Apr, 2024, 11:00

I downgraded to "appwrite": "^13.0.2", I didn't knew the syntax was different

Gaxve
18 Apr, 2024, 11:01

what should I do?

ideclon
18 Apr, 2024, 11:02

You should delete the node_modules/ folder, then run npm install again

Gaxve
18 Apr, 2024, 11:05

oh man I thought I already did, but it doesn't seem like it xd

Gaxve
18 Apr, 2024, 11:05

thank you, working now!

Gaxve
18 Apr, 2024, 11:05

🫰

ideclon
18 Apr, 2024, 11:06

Great! If your issue has been solved, you can mark this post as closed by adding "[SOLVED]" to the beginning of the title

Gaxve
18 Apr, 2024, 11:07

[SOLVED] Getting Invalid Query exception and it's not the 14.0.0 version problem.

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