使用Node.js的Firebase的Google Cloud Functions,我试图在两个嵌套的foreach循环中获取当前deltasnapshot的键。
第一级密钥是正确的'传入'
第二级无效' incomingABCDEFGHI' // ABCDEFGHI是帐户的唯一ID
第三级密钥正确' -ewroiu5o345o534535' // Firebase推送ID
的console.log(snapshot.key);
snapshot.forEach(function(accountSnapshot){
accountSnapshot.forEach(function(orderSnapshot){
console.log(snapshot.key);
console.log(accountSnapshot.key);
console.log(orderSnapshot.key);
});
});
由于某种原因,第二级键同时返回第一级和第二级组合键(没有斜线或空格)
DeltaSnapshot由数据库' onWrite'
触发任何人都有类似的东西吗?
答案 0 :(得分:0)
我遇到了完全相同的问题。如果我的路径是' 1/2/3',则键输出23而不是3.它们有一个方法输出一个孩子的完整路径,他们似乎省略了斜线。将其添加到index.js文件的顶部:
const functions = require('firebase-functions');
functions.database.DeltaSnapshot.prototype._fullPath = function () {
var out = (this._path || '') + '/' +(this._childPath || '');
if (out === '') {
out = '/';
}
return out;
}
我在GitHub上提交了一个问题,可以找到here。