我正在尝试查询 firebase,如果记录存在,我想要唯一的 key ,但似乎无法获取它。我的过滤器工作正常,但我不知道对象属性名称是什么,并且似乎无法在 firebase 上找到任何有帮助的内容。 .key() 总是返回错误。这是我返回对象时的样子
GET /js/init.js 200 5.048 ms - 207
GET /img/logo.png 200 2.376 ms - 2793
{ '-KP8qXgQRaeClqzKX1Lo': { email: 'bdole@gmail.com' } }
GET /sent 200 7.923 ms - 8110
这是我的代码
firebase.database().ref('/customers').orderByChild("email").equalTo(email).on("value", function(snapshot) {
console.log(snapshot.val());
},function (errorObject) {
console.log("The read failed: " + errorObject.code);
});
我需要该 key ,因为如果它存在,我需要在下一步中使用它。
最佳答案
您可以使用child_added
来跟踪新添加的记录并检索 key 。
firebase.database().ref('customers').on('child_added', function(snapshot) {
console.log(snapshot.key); //This will print that unique key
});
关于node.js - 查询Firebase并获取Key,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38944541/