getReference() vs. getChild()

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"?


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.


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

链接地址: http://www.djcxy.com/p/38622.html

上一篇: 将范围拆分成重叠范围的范围

下一篇: getReference()与getChild()