0
votes

the structure of my database looks like this:

enter image description here

each user has a document in the following collection, that document also contains a collection which holds the ids of the users that he is following.

the "posts" collection has the id of the user who posted it.

now i want to query it in such a way that i get all posts from the users that my user is following (ordered by timestamp)

this is what my user & post model look like:

class PostModel {
  final String id;
  final String creator;
  final String text;
  final Timestamp timestamp;
  
  
  PostModel({this.id, this.creator, this.text, this.timestamp});
}
class UserModel {
  final String id;
  final String email;
  final int following;
  final int followers;
  final String profileImgUrl;
  final String name;
  final String bio;
  final bool isVerified;
  final int postAmount;

  UserModel(
      {this.id,
      this.email,
      this.following,
      this.followers,
      this.profileImgUrl,
      this.name,
      this.bio,
      this.isVerified,
      this.postAmount});
}

can someone help me come up with an easy way to do this in flutter?

1

1 Answers

0
votes

Instead of a subcollection users you could have an array field to store the users otherwise you need to fetch the users subquery everytime which is expensive