如何批次多个操作?我发现Firestore https://firebase.google.com/docs/firestore/manage-data/transactions确实database有类似的资源。
在创建chat时,我想推一个新的消息集合。
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;
});
};发布于 2022-02-23 16:06:34
您所描述的内容可以通过以下方法完成:
const newRef = push(ref(db, "chats"));
set(newRef, {
chat_id: newRef.key,
...restOfYourObject
});对push的调用还没有导致任何网络流量,因为推送ID是一个纯客户端操作。
https://stackoverflow.com/questions/71233990
复制相似问题