问题描述
我有一个Firebase数据库,里面有Items。数据库中可能有多达1000个项目。我希望将45个随机孩子从数据库中拉出来使用。
任何想法如何做到这一点,而不是先把它们全部拉出来,然后把它们除草到我所需要的东西上去吧?
-Jhsu498984
item_name:my item 0
item_index:0
-Ynkkj93ov9
item_name:my item 24
item_index:24
然后用一个随机数发生器生成45个随机数(与item_index相匹配),然后查询这些特定的项。
>或
创建所有的项目,并在单独的节点中,保持它们的节点ref
item_refs
-Jhsu498984:true
-Ynkkj93ov9:true
然后你只需要加载item_refs(进入一个数组),然后从th中随机选择45 e阵列。然后查询这些项目。
I have a Firebase database with Items in it. There could potentially be up to 1000 items in the database.
I am looking to pull 45 random children out of the database to use.
Any idea how I can do this without pulling them all out first and then weeding them down to what I need?
Assign each item an index, 1-1000
-Jhsu498984
item_name: "my item 0"
item_index: 0
-Ynkkj93ov9
item_name: "my item 24"
item_index: 24
then, with a random number generator, generate 45 random numbers (which match the item_index) and query for those specific items.
or
create all of the items and in separate node, keep their node refs
item_refs
-Jhsu498984: true
-Ynkkj93ov9: true
then you just need to load in the item_refs (into an array) and then randomly pick 45 from the array. Then query for those items.
这篇关于从Firebase中检索一个随机的15个孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!