我正在处理firebase实时数据库v9,但是当我向数据库发送数据时,生成的每个文档的唯一id并不像在版本8中那样生成,而是以集合的名义映射数据,因此我不能推送另一个数据。我提供了一个图像来显示正在发生的事情。

function writeUserData(e) {
e.preventDefault();
set(ref(realtime, "customers/"), {Name:cname,Contact:
contact,
Serial:serial, Device: device, Served:
served, AmountC:amountc,
AmountP:amountp, Status:status }).then(() => {
toast.success("Data Saved Succefully");
})
.catch((err) => {
setError(err.message);
});
}发布于 2022-01-03 15:15:11
set()方法不生成随机ID,它只是在指定的路径上添加数据。必须使用push()生成随机ID:
push(ref(realtime, "customers/"), {...data}).then(() => {
console.log("Data added")
})https://stackoverflow.com/questions/70567724
复制相似问题