Back

Query inside array not working like expected

  • 1
  • Web
Hexi
4 Dec, 2023, 13:30

Hi I was looking if I could search into a array with the Query feuture. I saw Query.equal("accounts", [accountId]) would work but it doesnt seem to return anything

Tried this:

TypeScript
  let listings = await databases.listDocuments(
    process.env.LISTING_DB_ID,
    process.env.FUNDS_COLLECTION_ID,
    [
    Query.equal("accounts", [accountId])
    ]
  );
  console.log([accountId])
  console.log(listings)

But it returns 0 documents but I know accounts one has a document that has a array with that accountId

So it returns:

TypeScript
{ total: 0, documents: [] }
[ '656dd1ecc45f5eade4ec' ]

And if I remove the Query.equal:

TypeScript
{
  total: 1,
  documents: [
    {
      lister: '65269bd3282ac32a18e9',
      accounts: [ '656dd1ecc45f5eade4ec' ],
      amount: 150,
      verified: false,
      tags: [Array],
      payment_methods: [Array],
      paid: [],
      listed: true,
      locked_until: null,
      sold_amount: 0,
      price: 1200,
      '$id': '656dd307df95b6b7b7a0',
      '$createdAt': '2023-12-04T13:24:23.916+00:00',
      '$updatedAt': '2023-12-04T13:24:23.916+00:00',
      '$permissions': [],
      '$databaseId': '64ebb0361a869b05604d',
      '$collectionId': '64ebbb7ec778217d8079'
    }
  ]
}
[ '656dd1ecc45f5eade4ec' ]
TL;DR
The user is trying to search for documents in an array using the Query feature in the appwrite API. They have tried using Query.equal("accounts", [accountId]), but it is not returning any results even though they know there is a document with that accountId in the array. However, when they remove the Query.equal, it returns the expected document. Solution: The user should check the syntax and structure of their Query.equal statement and make sure it is correctly matching the structure of the array in the database. They can also refer to the GitHub link provided for more information on the issue.
Hexi
4 Dec, 2023, 13:38

Query inside array not working like expected

Drake
4 Dec, 2023, 15:48

This is unsupported at the moment. πŸ‘πŸΌ and see https://github.com/appwrite/appwrite/issues/2838

Rovar2000
14 Dec, 2023, 08:49

but why does it work on $id or other related attributes to appwrite?

Drake
14 Dec, 2023, 15:50

because $id is not an array

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