Back

[Solved] Query for null value

  • 0
  • Android
  • Databases
  • Web
Alsemo
25 Nov, 2023, 15:06

Hi,

I have a document which have a key named "vendor_id" which is by default, null. Then it can be changed to specific User Id. What I'm trying to do is to get all documents which is either null and have a specific user id.

Use case, to get all documents which still doesnt have any vendor_id and also those that have his user id as the key in vendor_id.

My question is how to query a null value in a key, I tried something like

Query.equal("vendor_id", [``, ${user?.$id}]),

and it doesnt work. Thanks in advance.

TL;DR
The user is asking how to query for documents that have a null value or a specific user id in the "vendor_id" key. They tried using Query.equal("vendor_id", [``, `${user?.$id}`]) but it didn't work. The solution is to use the isNull query, which can be found at <https://appwrite.io/docs/products/databases/queries>. The thread also includes a link to a GitHub issue for further discussion and a suggestion to like the issue.
Drake
25 Nov, 2023, 16:19
Alsemo
25 Nov, 2023, 17:03

Hi Steven, if I use

Query.isNull("vendor_id"), it will only get the document if only the key null, so if I also want to get get documents that also have vendor_id as my user.$id, I would have to create another function that's something like Query.equal("vendor_id", [user.$id]) that will pull another batch of documents instead.

What I was hoping to achieve is to use something like Query.equal("vendor_id", [NULL, user.&id]) or Query.between("vendor_id", NULL, user.$id) (If I read the Query.between purpose correctly) that will pull both documents that have NULL vendor_id and my user.$id.

Drake
25 Nov, 2023, 17:04

Oh sorry, I misread...you're trying to do an OR query which isn't supported yet.

Alsemo
25 Nov, 2023, 17:04

ah ok

Alsemo
25 Nov, 2023, 17:04

Thanks for the clarification

Alsemo
25 Nov, 2023, 17:05

Is it something that being considered to be implemented?

Alsemo
25 Nov, 2023, 17:07

[Solved] Query for null value

Drake
25 Nov, 2023, 17:31
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