Swift/Firestore查询排名系统中的集合

Swift/Firestore查询排名系统中的集合,swift,database,firebase,google-cloud-firestore,nosql,Swift,Database,Firebase,Google Cloud Firestore,Nosql,我越来越感激我从SO社区学到的东西,所以提前感谢您抽出时间 以下是我需要完成的工作的总结: 假设我在Firestore集合中有1000个用户,每个用户都有一个关联分数。用户还可以相互跟踪。假设“用户A”需要对其跟踪的100个用户运行查询,同时将每个用户的排名保持在全球1000个用户之内。也就是说,用户A正在跟踪排名1的人、排名237的人、排名999的人等 我的数据目前的结构如下所示: user_information (Collection) -- user_id (Document) ----

我越来越感激我从SO社区学到的东西,所以提前感谢您抽出时间

以下是我需要完成的工作的总结:

假设我在Firestore集合中有1000个用户,每个用户都有一个关联分数。用户还可以相互跟踪。假设“用户A”需要对其跟踪的100个用户运行查询,同时将每个用户的排名保持在全球1000个用户之内。也就是说,用户A正在跟踪排名1的人、排名237的人、排名999的人等

我的数据目前的结构如下所示:

user_information (Collection)
-- user_id (Document)
---- user_score (Int Field) <- the field in which the query is sorted by
users (Collectiion)
-- user_id (Document)
---- following_users (Collection) <- Running the query on these users
------ user_id (Document)
用户信息(收集)
--用户id(文档)

----在我回答你的最后一个问题之前,让我分享一下:我的方法是用以下方式调整数据库结构:

user_information (Collection)
-- user_id (Document)
---- user_score (Int Field) <- the field in which the query is sorted by
users (Collectiion)
-- user_id (Document)
---- following_users (Array Field) [Array field of user_id's this user is following]
await leaderboard_query = db.collection(user_information).where('followerCount', '>', 0).orderBy('user_score');