简体   繁体   English

查询Firebase(NoSQL)数据的子集

[英]Query subset of Firebase (NoSQL) data

I have a Firebase (NoSQL) collection of say 5,000 "players". 我有一个说有5,000个“玩家”的Firebase(NoSQL)集合。 Each day I want to query a subset of those players in order to perform some operation. 每天我都想查询这些播放器的子集以执行一些操作。 My question is, what is the best way to do that? 我的问题是,最好的方法是什么?

As best as I can tell, there is no way to perform such a query within Firebase directly. 据我所知,无法在Firebase中直接执行此类查询。 So for example, I cannot say "Collection of 5,000 players, give me all of the players which match ANY of these identifiers". 因此,例如,我不能说“收集5,000名玩家,给我所有与这些标识符中的任何一个匹配的玩家”。 If that is an option, please advise. 如果可以的话,请告知。

One option I thought of would be to create a new collection each day with the identifiers of players I am interested in performing operations on. 我想到的一个选择是每天创建一个收藏,其中包含我有兴趣对其进行操作的玩家的标识符。 Would this be the preferred method in Firebase? 这将是Firebase中的首选方法吗? IE, I'd create a collection like 20190105Game and it would contain the identifier subset. IE,我将创建一个像20190105Game的集合,它将包含标识符子集。 I'd query that collection first, then go to the Players collection to get collection.where("identifier", "==", "other_identifier") 我先查询该集合,然后转到Players集合以获取collection.where("identifier", "==", "other_identifier")

Is there a better way? 有没有更好的办法?

If you want to filter a subset of the players, you have two options: 如果要过滤播放器的子集,则有两个选择:

  1. Include the condition for the subset into your query. 在查询中包括该子集的条件。 Eg playersRef.where("subset", "=", 2).where("othercondition", "=", "value").orderBy("somefield").limit(2) 例如playersRef.where("subset", "=", 2).where("othercondition", "=", "value").orderBy("somefield").limit(2)

  2. Create a (sub)collection for the subset of players. 为玩家的子集创建一个(子)集合。

Neither is pertinently better than the other, it all depends on your exact use-cases. 两者都不比另一个更好,这完全取决于您的确切用例。 I'd typically go for the first option, unless I have a use-case where tht is impossible due to my other query or throughput requirements. 我通常会选择第一个选项,除非我有一个用例,由于我的其他查询或吞吐量要求,这是不可能的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM