擅长:python、mysql、java
<p>Firebase实时数据库是<a href="https://firebase.google.com/docs/database/web/structure-data#avoid_nesting_data" rel="nofollow noreferrer">one big JSON tree</a>:</p>
<blockquote>
<p>when you fetch data at a location in your database, you also retrieve
all of its child nodes.</p>
</blockquote>
<p>最佳实践是<a href="https://firebase.google.com/docs/database/web/structure-data#fanout" rel="nofollow noreferrer">denormalize your data</a>,为同一数据创建多个位置(节点):</p>
<blockquote>
<p>Many times you can denormalize the data by using a query to retrieve a
subset of the data</p>
</blockquote>
<p>在您的例子中,您可以创建名为“categories”的第二个节点,其中您只列出类别名称。</p>
<pre><code>/cat1
/...
/cat2
/...
/cat3
/...
/cat4
/...
/categories
/cat1
/cat2
/cat3
/cat4
</code></pre>
<p>在这种情况下,可以使用<a href="https://firebase.google.com/docs/database/web/read-and-write#updating_or_deleting_data" rel="nofollow noreferrer">update() method</a>同时写入多个位置。</p>