A
A
ashyr962020-10-21 09:42:55
Android
ashyr96, 2020-10-21 09:42:55

How to get documents from Firestore from a list?

There is a list of friends (user-id, maybe several hundred) and there are documents with user data.
Question: how to get the data of the desired users using one query (using this selection)?
For example user1 has friends List['user4', 'user2', 'user19', ..n].
How to get these friends' documents for further display (preferably in a Stream)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem441, 2020-11-21
@Artem441

try to make a list in the document, to which the id-document of the desired user will be added, and then you will simply call it.

import 'package:cloud_firestore/cloud_firestore.dart';

class users{

  var userId = 'это id-документа нашего юзера, который выполняет действие';

  //здесь мы берем из его документа список id-документов его друзей
  //который как я понимаю тоже постепенно наполнятеся
  var pathUsers = FirebaseFirestore.instance
      .collection('users').doc(userId).get().then((value) => value.data()['arrayOfPath']);

  
  //здесь можем обращаться к данным каждого юзера-друга
  var getNeedUserData = FirebaseFirestore.instance
      .collection('users').doc(PATHS[index]);


}

I'm certainly not sure what will work, tk. I am a beginner myself, so if you can write)))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question