[英]How to add new data in firebase without the unique keys
I'm using it in react native app to save the purchase history in firebase with only 0,1,2,3,4.... keys not the system generated unique key我在 React Native 应用程序中使用它来保存 firebase 中的购买历史记录,只有 0,1,2,3,4.... 键不是系统生成的唯一键
I'm using this below syntax我正在使用下面的语法
firebase2.database().ref('user_data/' + my_key+"/purchase_history").push(MY_DATA)
I want to remove the key between purchase_history and 0
and when I add the new data then it should be visible like 0 then 1 then 2 then 3 and so on......
我想删除
purchase_history and 0
之间的键,当我添加新数据时,它应该是可见的,例如0 then 1 then 2 then 3 and so on......
If I correctly understand your question, you should use the set()
method instead of the push()
one, as follows:如果我正确理解你的问题,你应该使用
set()
方法而不是push()
) 方法,如下所示:
const newKey = "0"; // Or "1", "2", "3"....
firebase2.database().ref("user_data/" + my_key + "/purchase_history/" + newKey).set(MY_DATA);
As a matter of fact, push()
generates a new child location using a unique key which is automatically generated by the Realtime Database (ie -MR99pAG....
).事实上,
push()
使用由实时数据库自动生成的唯一键(即-MR99pAG....
)生成一个新的子位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.