How do I batch multiple operations? I found this resource for Firestore https://firebase.google.com/docs/firestore/manage-data/transactions does database have something similar.
I wanted to push a new message collection when chat is created.
export const newChat = () => {
return push(ref(db, "chats"),{
...
})
.then((data) => {
update(ref(db, `chats/${data.key}`), {
chat_id: key,
});
//push(ref(db, `messages/${data.key}`), {
//text: "hello"
//});
})
.catch((error) => {
return error;
});
};
What you're describing can be accomplished with:
const newRef = push(ref(db, "chats"));
set(newRef, {
chat_id: newRef.key,
...restOfYourObject
});
The call to push does not cause any network traffic yet, as push IDs are a pure client-side operation.