简体   繁体   English

是否可以为子对象定义limit()?

[英]Is it possible to define limit()'s for child objects?

I am looking to retrieve the first 10 records of a 1000 in a dataset, but each of those records has a property with a 1000 records itself - is there a way to limit the grandchild to only return X records as well? 我正在寻找在数据集中检索前1000条记录的前10条记录,但是这些记录中的每条记录都具有一个本身具有1000条记录的属性-是否有办法限制孙子项也只返回X条记录? Something like: 就像是:

firebaseRef.limit(10).limit(10, childPropertyName).once(...) firebaseRef.limit(10).limit(10,childPropertyName).once(...)

(when I say 1000, it could be 1,000,000, I didn't want to include all the zeros) (当我说1000时,可能是1,000,000,我不想包含所有零)

If not, are there any workarounds or strategies to deal with large nested sets? 如果没有,是否有任何解决方法或策略来处理大型嵌套集?

One possibility is to de-nest them. 一种可能性是对它们进行去巢。 The grandchild could be split out out into its own list with the same key names as its former parent. 孙子可以拆分成自己的列表,并使用与前父项相同的键名。 Is that the best way to go? 那是最好的方法吗?

No, there isn't. 不,没有。 We're working on ways to do this but they won't be released for a while. 我们正在研究实现此目的的方法,但暂时不会发布它们。

In the meantime, I'd suggest building a separate index that simply lists the names of the top-level children. 同时,我建议您建立一个单独的索引,该索引仅列出顶级子级的名称。 Then you can do a "limit(10)" on that index, and then do a limit(10) on a path constructed using each of those keys. 然后,您可以在该索引上执行“ limit(10)”,然后在使用这些键中的每一个构造的路径上执行limit(10)。

So your code would look like this: 因此,您的代码如下所示:

indexRef.limit(10).once("child_added", function(snapshot) {
  dataRef.child(snapshot.name()).limit(10).once(...);
} 

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

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