Back

[Question]: searching by $id.

  • 0
  • Web
gaurav_ch
17 Aug, 2023, 10:04

Hi, I am trying to run a query which used $id of the document but I keep getting an error that $id not found. Do I have to make an index for $id or $id is privately used by appwrite? In the meantime I have added an attribute for my own custom user_id implementation.

TL;DR
User is trying to run a query using $id of a document but keeps getting an error that $id is not found. They are asking if they need to create an index for $id or if $id is only privately used by appwrite. The user has added their own custom user_id implementation in the meantime. Solution: Create an index for $id or use a different attribute for custom user_id implementation.
safwan
17 Aug, 2023, 11:29

What version of Appwrite are you on?

gaurav_ch
17 Aug, 2023, 11:30

v 1.3.8

safwan
17 Aug, 2023, 11:31

Can you show your code?

gaurav_ch
17 Aug, 2023, 11:33

I am just using a Query:

TypeScript
await this.getDatabase(this.getClient()).listDocuments(environment.api.database_id, collectionId, [
Query.equal('$id',1)]);
safwan
17 Aug, 2023, 11:35

Did you try creating an index for it?

gaurav_ch
17 Aug, 2023, 11:40

no, that is what I am confused about. do I need to create an index or is $id not available to be used outside of appwrite?

safwan
17 Aug, 2023, 11:41

I don't think $id is restricted like that. Why not try creating and check it?

gaurav_ch
17 Aug, 2023, 11:41

πŸ‘

Drake
17 Aug, 2023, 20:21

why not use getDocument()? 🧐

gaurav_ch
18 Aug, 2023, 01:33

for getDocument I need the document id. I am asking whether I can use $id for queries or not as I tried and got an error that $id not found.

Drake
18 Aug, 2023, 01:34

I don't understand the difference

Drake
18 Aug, 2023, 01:34

This is finding a document with $id == 1.... Which is getDocument(DB, collection, 1)

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