'(Firebase Realtime Database| React) How to add data to a firebase realtime database without key?
I want to structure my data something like this with movieId added to wishlist when i favourite it but i don't know how to go about it. I was using push() but that adds a generated key and then adds the movie which i don't want. How can I achieve this?
Code that adds first movie
set(ref(db,`users/${auth.currentUser?.uid}/wishlist/`),{[movieId]:true})
Code that adds subsequent movies
const wishlistRef = ref(db, `users/${auth.currentUser?.uid}/wishlist`);
const newWishlistRef = push(wishlistRef);
set(newWishlistRef, {
[movieId]:true
});
Solution 1:[1]
This does the trick
const nodeRef = child(ref(db), `users/${auth.currentUser?.uid}/wishlist/` + movieId); // id = custom ID you want to specify
set(nodeRef, true )
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | H.b |


