Back

Not being able to Query string array documents properly

  • 0
  • Databases
  • Web
Dynerus
11 Feb, 2024, 01:19

I was trying to query documents based on multiple variables. Currently I am using Query.equal('users', [selectedUser, currentUser]) Seems this doesn't work as expected. I also couldn't find a Query.contains or something similar

Any workaround?

TL;DR
Developers are having issues with querying string array documents properly. They are using `Query.equal('users', [selectedUser, currentUser])` but it doesn't work as expected. There is a workaround mentioned in a post from Feb 25 - 2022, which suggests using `Query.search` as a hack. The developer is wondering if this issue will be fixed soon since it has been about 2 years. Solution: To query documents based on multiple variables, developers can use `Query.search` as a workaround for now. It is unclear when the issue will be fixed.
Dynerus
11 Feb, 2024, 01:21

Just noticed a post from Feb 25 - 2022 about this exact issue talking about Query.search as a hack. Is it expected to be fixed soon since it's been about 2 years now?

Dynerus
11 Feb, 2024, 01:33

This can't be the right way to do it? (works tho)

TypeScript
      let chat = await databases.listDocuments(
        process.env.NEXT_PUBLIC_DATABASE,
        process.env.NEXT_PUBLIC_DATABASE_CHATS,
        [
          Query.equal(
            'users',
            `${currentUser},${selectedUser}`
          ),
        ]
      )

      if (!chat.documents.length) {
        chat = await databases.listDocuments(
          process.env.NEXT_PUBLIC_DATABASE,
          process.env.NEXT_PUBLIC_DATABASE_CHATS,
          [
            Query.equal(
              'users',
              `${selectedUser},${currentUser}`
            ),
          ]
        )
      }

saving it to users attribute as:

TypeScript
users: `${currentUser},${selectedUser}`
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
Copyright © 2024 Appwrite