简体   繁体   中英

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

在此处输入图像描述

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......

If I correctly understand your question, you should use the set() method instead of the push() one, as follows:

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.... ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM