i want to fetch user followers from database and i double checked everything but still not able to get the list. here's my user_api code . there could be a mistake in query i guess -
Future<List<model.Document>> getFollowers(String uid) async {
final documents = await _db.listDocuments(
databaseId: AppConstants.APPWRITE_DATABASE_ID,
collectionId: AppConstants.APPWRITE_USERS_COLLECIION,
queries: [
Query.equal('followers', uid)
]
);
return documents.documents;
}```
it looks good, have you created an index on followers field?
and could you pls send the error message
here's my controller code -
Future<List<UserModel>> getFollowers(String uid) async {
final followersDocs = await _userAPI.getFollowers(uid);
return followersDocs.map((e) => UserModel.fromMap(e.data)).toList();
}
provider - final getFollowersProvider = FutureProvider.family((ref, String uid) async{
final UserProfileController = ref.watch(userProfileControllerProvider.notifier);
return UserProfileController.getFollowers(uid);
});
and here i am displaying - ref.watch(getFollowersProvider(user.uid)).when(
data: (followers) {
print('Followers Count: ${followers.length}');
print('User UID: ${user.uid}');
return ListView.builder(
itemCount: followers.length,
itemBuilder: (BuildContext context, int index) {
final follower = followers[index];
return SearchTile(userModel: follower);
},
);
},
error: (error, st) => ErrorText(error: error.toString()),
loading: () => const Loader(),
),
followers present in my usermodel - class UserModel {
final String email;
final String name;
final List<String> followers;
and there's no error. the list is just not displaying. and printing followers.length = 0
I think i am using wrong query because the followers are in list but idk what would be the right query to use
as here followers field is a list its still wip here you can see an issue about the same https://github.com/appwrite/appwrite/issues/2838
you can trying using Query.search (as mention in one of the comments it kinda works) or filter in the client side as per the requirment
i tried using query.search. still not working :_
Yes i tried using listDocument its not working, also not getting desired attribute data
rn something like Query.contains is not present to search from a list but you can do filter it in the client side π
whats exactly not working for you @Pradhumansinh Padhiyar
Something like
SELECT username, email, password, firstname, lastname from tbl_users WHERE lastname = "Ranjan"
How can i achieve something like this using Db collection ?
add a query as Query.equal('lastname', 'Ranjan') and make a index for the lastname parameter in the appwrite console
how could i do that?
actually depends on what exactly you are tying to do
Some days Ago I am also Facing this issue You need To Specify your attribute into the indexes Section
Recommended threads
- Errore 403
Ho errore 403 ma il package name Γ¨ corretto
- Cannot create sites using Flutter framew...
Cannot goto next step, it shows error "missing buildRuntime". I need to select "other" framework then deploys fail, go back to site settings and change "other" ...
- Appwrite mariadb container suddenly usin...
I'm hosting an instance of appwrite since months and updated to 1.8.0 couple of weeks ago. Everything worked fine, but today I noticed that my server is lagging...