简体   繁体   English

如何在没有唯一键的情况下在 firebase 中添加新数据

[英]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.

相关问题 如何使用 flutter 向 firebase 添加新数据? - how to add new data to firebase with flutter? 如何在 firebase 9 中的现有 object 中添加新键和值而不覆盖以前的数据 - how to add a new key and value to an existing object in firebase 9 without overwriting previous data 添加新数据(不是更新)到 Firebase - Add new data (not update) to Firebase 如何在 firebase 实时数据库 javascript 中用新数据添加以前的数据 - How to add previous data with new one in firebase realtime database javascript 在 Firebase 中更新用户位置而不生成新的唯一 ID - Updating user location without generating new unique ID in Firebase (Firebase Realtime Database| React) 如何在没有密钥的情况下将数据添加到 firebase 实时数据库? - (Firebase Realtime Database| React) How to add data to a firebase realtime database without key? 如何在firebase数据库中添加数据 - How to add data in firebase database 有没有办法在不使用控制台的情况下向我的 Firebase 项目添加新站点? - Is there a way to add a new site to my Firebase project without using the Console? 如何使用 Firebase 在组中添加新成员 - How to add new members in Group using Firebase 如何使用 Firebase 将新数据推送到数组 - How to push new data to Array with Firebase
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM