Back

[SOLVED] how to get database collections attribute value using flutter ?

  • 1
  • Flutter
Pradhumansinh Padhiyar
30 May, 2023, 09:00

business_owner_id will be unique value but return value only gives me document list not collection attribute data

https://appwrite.io/docs/models/documentList

TL;DR
The user was looking for a solution on how to get database collection attribute values using Flutter. They found the solution by using `print(test[0].data['business_name'])`. They also shared a screenshot of the database structure. The thread includes some discussion about accessing attribute values and the code needed for querying the database. The solution provided is to specify the `business_owner_ID` in the indexes and use a query to retrieve the desired documents. The thread also includes a link to the documentation for `DocumentList`.
D5
30 May, 2023, 09:05

In such case: Query.equal("bussines_owner_ID", ["a123123qqwe"]) Should return all documents that have an attribute business_owner_id that equals to a123123q

joeyouss
30 May, 2023, 09:08

I understand, it was an example. Since business owner ID is unique, you can use that ID as your searchable key rather then running the query you mentioned -> as @D5 pointed.

D5
30 May, 2023, 09:11

Full example:

TypeScript
import 'package:appwrite/appwrite.dart';

void main() async {
    final client = Client()
        .setEndpoint('https://cloud.appwrite.io/v1')
        .setProject('[PROJECT_ID]');

    final databases = Databases(client);

    try {
        final documents = await
            databases.listDocuments(
                '[DATABASE_ID]',
                '[COLLECTION_ID]',
                    [
                Query.equal("bussines_owner_ID",["a123123qqwe"])
                    ]
        );
    } on AppwriteException catch(e) {
        print(e);
    }
}
Nikunj Panchal 🌿
30 May, 2023, 09:26

You need to specify your bussines_owner_ID into Indexes after that your query working

Pradhumansinh Padhiyar
30 May, 2023, 09:28

Something like this ?

Nikunj Panchal 🌿
30 May, 2023, 09:29

Yessss

Nikunj Panchal 🌿
30 May, 2023, 09:29

Key And Attribute names are same

Nikunj Panchal 🌿
30 May, 2023, 09:29

bussines_owner_ID

Pradhumansinh Padhiyar
30 May, 2023, 09:30

It should be same or not ?

D5
30 May, 2023, 09:31

In the latest version it's not needed using attributes, however very recommended since it improves performance

Nikunj Panchal 🌿
30 May, 2023, 09:31

It should be same

Pradhumansinh Padhiyar
30 May, 2023, 09:33

And how do you access attribute value ? like test[0].@business_name

Nikunj Panchal 🌿
30 May, 2023, 09:33

test[index].attributeName

Pradhumansinh Padhiyar
30 May, 2023, 09:34

🥲

Pradhumansinh Padhiyar
30 May, 2023, 09:35

test[0].$collectionId

For this is showing me correct collectionID

D5
30 May, 2023, 09:35

Could you please send all the code? (Related to appwrite)

Pradhumansinh Padhiyar
30 May, 2023, 09:37

🥲

Pradhumansinh Padhiyar
30 May, 2023, 09:43

{ "total": 5, "documents": [ { "$id": "5e5ea5c16897e", "$collectionId": "5e5ea5c15117e", "$databaseId": "5e5ea5c15117e", "$createdAt": "2020-10-15T06:38:00.000+00:00", "$updatedAt": "2020-10-15T06:38:00.000+00:00", "$permissions": [ "read(any)" ] } ] }

i can only able to access this $ keys only but not able to access my collection attributes

Nikunj Panchal 🌿
30 May, 2023, 09:45

Share SS of Db

Pradhumansinh Padhiyar
30 May, 2023, 09:46
Pradhumansinh Padhiyar
30 May, 2023, 09:58

I got the solution

I need to use something like this

print(test[0].data['business_name']);

Pradhumansinh Padhiyar
30 May, 2023, 09:59

Thank You Guys @joeyouss @Nikunj Panchal 🌿 @D5

Nikunj Panchal 🌿
30 May, 2023, 10:19
D5
30 May, 2023, 10:26

[SOLVED] how to get database collections attribute value using flutter ?

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