getReference() vs. getChild()

时光毁灭记忆、已成空白 提交于 2021-02-04 17:41:08

问题


I was wondering what the difference between database.getReference("foo/bar/123") and database.getReference("foo").child("bar").child("123") is?

I'm assuming that the later one will load the complete "foo" object whereas database.getReference("foo/bar/123") just loads the "123" object?

Is my assumption correct or what is the correct / most efficient way to only load data of "123"?


回答1:


The two are equivalent. You can inspect this manually this by printing the toString() format for both References.

References are cheap - there's nothing inefficient about either solution. Neither one has yet loaded any data. A Reference is just a pointer to a location in the database.




回答2:


It should not make a difference, a reference is not actually accessed when instantiated. This is the most relevant document I can find,

https://firebase.google.com/docs/reference/node/firebase.database.Reference

The docs don't say it explicitly, but requests are only performed when using the .set() or .on() methods



来源:https://stackoverflow.com/questions/42551249/getreference-vs-getchild

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!