Back

[SOLVED] Queries not working

  • 1
  • Self Hosted
  • Web
WildAnimal
26 May, 2023, 08:17

I noticed that official example using Query at the front end like this:

TypeScript
import { Client, Databases, Query } from "appwrite"

But I use it in node-appwrite at the server side like this:

TypeScript
import { Client, Databases, Query } from "node-appwrite"

Is it wrong about this? Is it can not work in node-appwrite sdk.

TL;DR
Issue: The user is experiencing queries not working in their node-appwrite application. They are using the Query.equal method but not getting any results. Solution: The issue was caused by a mistake in the user's code. They had changed the node-appwrite API request method from axios to fetch and lost the query parameter. They resolved the issue by reverting the change and the queries started working again.
Drake
26 May, 2023, 15:15

did you run the migrate command after upgrading?

Drake
26 May, 2023, 15:15

that appwrite is a client SDK. node-appwrite is a server sdk. see https://appwrite.io/docs/sdks

WildAnimal
27 May, 2023, 12:11

yes, I have run the migrate command. 😫

Drake
27 May, 2023, 14:52

It works for me 🧐

Drake
27 May, 2023, 14:52

What results do you get if you filter for disabled = true?

WildAnimal
28 May, 2023, 07:02

It still lists all documents, same as never change the conditions. All conditions are not working at all. But the queries work well in local development env.

WildAnimal
28 May, 2023, 08:06
TypeScript
  const client = new Client().setEndpoint(appwrite_endpoint).setProject(appwrite_project).setKey(appwrite_key);
  const databases = new Databases(client);
  const appwrite_conditions = [
    Query.select(['$id', 'messageTitle']),
    Query.equal('disabled', false),
    Query.limit(10),
    Query.orderDesc('created'),
  ];

  const purpose = (context.query.purpose as string) ?? '';
  if (purpose) {
    appwrite_conditions.push(Query.equal('systemPurposeId', purpose));
  }

  return databases.listDocuments(appwrite_databaseId, appwrite_collectionId, appwrite_conditions).then(
    (res: any) => {
      return {
        props: {
          conversations: res.documents,
          purpose: purpose,
        },
      };
    },
    (err) => {
      return {
        props: {
          error: {
            message: err.message ?? 'Unknown error.',
            status: err.code ?? 500,
          },
        },
      };
    },
  );
Drake
28 May, 2023, 15:14

You have a local Appwrite instance and another Appwrite instance?

WildAnimal
28 May, 2023, 21:05

local for dev another at remote for prod

Drake
28 May, 2023, 22:16

You definitely need to make sure you're connecting to the right instance...and the schemas match

WildAnimal
29 May, 2023, 01:02

How to view the logs of get documents with query to confirm the request url and test it?

Drake
29 May, 2023, 01:03

Maybe traefik logs if it's enabled

Bouahaza
29 May, 2023, 01:09

To order you need to set "$createdAt"

Bouahaza
29 May, 2023, 01:10

With $

WildAnimal
29 May, 2023, 01:16

I have list all containers with command: docker ps And got the container id then checked the logs of traefik:2.7 image. There are only tow lines contents:

TypeScript
time="2023-05-27T02:20:01Z" level=info msg="Configuration loaded from flags."
time="2023-05-27T02:20:04Z" level=error msg="the router appwrite_realtime_wss@docker uses a non-existent resolver: dns"
Bouahaza
29 May, 2023, 01:18

accesslog is disable by default

WildAnimal
29 May, 2023, 01:19

You are right. But I defined a customized attribute named created.

Bouahaza
29 May, 2023, 01:19

Ok

WildAnimal
29 May, 2023, 01:25

Thanks.

Chola
29 May, 2023, 07:27

I too have an issue with querying a collection using Query.equals('attribute','123') , i get nothing in return no matter what i do. I'm using cloud Appwrite so i cannot update it

Drake
29 May, 2023, 07:28

Feel free to create a new post in <#1072905050399191082>

WildAnimal
6 Jun, 2023, 02:17

This post has been resolved. Earlier, I had changed the node-appwrite api request method from axios to fetch and losted the query parameter. Now, I have resumed and it is work well. It's all my fault.

safwan
6 Jun, 2023, 07:01

[SOLVED] Queries not working

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