Firebase 只存储对象。JS 客户端使用索引作为键将数组转换为对象。因此,例如,如果您使用以下数组存储以下数组set:
comments: [
  "comment1",
  "comment2"
]
在 Forge(图形调试器)中,它将显示为:
comments:
   0: comment1
   1: comment2
鉴于此,将评论的 ID 直接存储为密钥的优点是您可以直接在安全规则中引用它,例如,使用如下表达式:
root.child('comments').hasChild($comment)
为了生成这些评论的唯一参考,请使用push(https://www.firebase.com/docs/managing-lists.html):
var commentsRef = new Firebase("https://<example>.firebaseio.com/comments");
var id = commentsRef.push({content: "Hello world!", author: "Alice"});
console.log(id); // Unique identifier for the comment just added.