您可以
DataSnapshot.hasChild用来确定某个孩子是否存在。
usersRef.once('value', function(snapshot) { if (snapshot.hasChild(theDataToAdd)) { alert('exists'); }});但这将下载所有数据
usersRef并在客户端上执行检查。通过加载更具针对性的引用,只为您要检查的用户下载数据,效率会更高:
usersRef.child(theDataToAdd).once('value', function(snapshot) { if (snapshot.exists()) { alert('exists'); }});


