我希望在使用云函数时从firebase push命令中获得密钥。
const params = {
date: Date.now(),
movie,
movieId: movie.id,
userId: user.uid,
group: 'home',
type: 'watched'
};
const pastRef = event.data.adminRef.root.child(`pastActivity/${user.uid}`);
var newPostRef = pastRef.push().set(params);
var postId = newPostRef.key;
console.log(postId); //undefined
然而,postId返回时是未定义的。我已经尝试了其他一些建议的方法,但没有任何结果。
发布于 2018-12-24 07:10:09
如果不需要newPostRef
变量,则可以使用较短的版本
//var newPostRef = pastRef.push().set(params);
//var postId = newPostRef.key;
const newPostRefKey = pastRef.push(params).key
//this pushes the data and returns the key
https://stackoverflow.com/questions/48606190
复制相似问题