Firebase 在 setValue 中保存带有自定义键结果的数据不是函数错误



保存到Firebase时,我正在尝试设置自定义密钥,而不是在常规推送中使用Firebase生成的密钥。 这似乎很简单,因为这是我看到其他人这样做的方式。 谁能看出我正在做的事情有什么问题?

export const startAddMovie = (movieData = {}) => {
return (dispatch, getState) => {
const uid = getState().auth.uid; 
const {
title = '',
ratingComment = '',
rating = '',
createdAt = 0,
} = movieData;
const movie = { title, ratingComment, rating, createdAt };

// the next line works perfectly but it sets the ID of the new entry for me
database.ref(`users/${uid}/movies`).push(movie);
// the next line fails with error _firebase2.default.ref(...).child(...).setValue is not a function
database.ref(`users/${uid}/movies`).child('1234').setValue(movie);

在文档中的实时数据库中设置节点的方法有很多种。这是我所知道的一种可能的语法,它将实现您想要实现的目标。将故障线替换为此

database.ref(`users/${uid}/movies/1234`).set(movie);

最新更新