Back

Is there any way to add indexes on documents throw code

  • 2
  • Databases
  • Web
Ashraf_Chowdury
1 Apr, 2023, 07:36

Is there any way to add indexes on database documents when we createDocument.

TL;DR
The user is asking if it is possible to create indexes on database documents programmatically. They mention that creating separate indexes for each user may not be a good idea. Another user suggests creating an index for the userId attribute in the collection and querying to return the specific files for that user. The original user provides more context about their database and asks for code examples. Another user clarifies that indexes are typically created beforehand and asks for more details about the user's use case. Solution: It is not possible to add indexes to individual documents when creating them. Indexes are created for a collection and use the attributes of that collection. To retrieve
safwan
1 Apr, 2023, 07:40

I'm trying to understand your use case to suggest a good approach.

So indexes are created for a Collection., using the Attributes of that collection.

safwan
1 Apr, 2023, 07:41

So one Collection/table can have as many indexes as you want, but I don't see how creating a new document would be useful for adding an index. Help me out in understanding what you're trying to do lol

Ashraf_Chowdury
1 Apr, 2023, 08:53

I have multiple documents on a collections which is created by the users, so one user can save max 3 files ( the user attribute have the user id ), now if a user needs their saved data, instead of fetch all docs I want fetch only those docs which is matched with user id.

Drake
1 Apr, 2023, 14:51

You typically create the indexes beforehand just like you create the attributes before using the collection 🧐

Ashraf_Chowdury
2 Apr, 2023, 09:35

Steven, Can you please explain how I need to write the code?

Ashraf_Chowdury
2 Apr, 2023, 09:41

My database is like this: In a collection, all users can save max 3 files with their auth id, now I want to fetch the 3 specific files which that user created by his or her Id instead of all the files.

safwan
2 Apr, 2023, 10:03

im thinking if you can do this without having to create seperate indexes for each user

safwan
2 Apr, 2023, 10:04

just create an index for the userId attribute in the collection, and query to return the ones that match the input userId

safwan
2 Apr, 2023, 10:06

Yeah it doesn't make sense to create an index for each user. Based on how many users you're expecting, you can end up creating thousands of indexes which I dont think is a good idea

Ashraf_Chowdury
2 Apr, 2023, 10:23

It make sense 100%

Ashraf_Chowdury
2 Apr, 2023, 10:24

is their any way to create index throw code just like attribute?

Ashraf_Chowdury
3 Apr, 2023, 18:18

Thanks for the link, Steven 👍

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