繁体   English   中英

(Firebase Realtime Database| React) 如何在没有密钥的情况下将数据添加到 firebase 实时数据库?

[英](Firebase Realtime Database| React) How to add data to a firebase realtime database without key?

数据结构

我想像这样构造我的数据,当我喜欢它时将 movieId 添加到愿望清单,但我不知道如何 go 。 我正在使用 push() 但它添加了一个生成的密钥,然后添加了我不想要的电影。 我怎样才能做到这一点?

在此处输入图像描述

添加第一个电影set(ref(db,`users/${auth.currentUser?.uid}/wishlist/`),{[movieId]:true})

添加后续电影的代码

const wishlistRef = ref(db, `users/${auth.currentUser?.uid}/wishlist`);
        const newWishlistRef = push(wishlistRef);
        set(newWishlistRef, {
            [movieId]:true
        });

这就是诀窍

const nodeRef = child(ref(db), `users/${auth.currentUser?.uid}/wishlist/` + movieId); // id = custom ID you want to specify 

set(nodeRef,  true )

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM