简体   繁体   English

如何使用 firebase 9 push 来实现这一点?

[英]How do I achieve this using firebase 9 push?

I switch to firebase 9 and want to achieve following我切换到 firebase 9 并希望实现以下

customers
   -MomOdRNzkqr9vDk_MmE:"ptwXJ7JRAASFgd3KoS2fQyQhyV613"
   -Myb3b_2W-7FTlsZvXCO:"QZOQ43DGYwfu4djlZ5EjEVksOr53"

I am trying the following我正在尝试以下

const customerSelectedRef = ref(db,`/serviceProvider/${user1.uid}/moneyCollector/customers`);
const customerSelectedRefPush = push(customerSelectedRef);
set(customerSelectedRefPush, customerSelected); // not wanted to use {customerSelected} which gives key value pair under push id

How could add value directly to push id?怎么能直接为push id增值?

1

The old method was旧方法是

  firebase
    .database()
    .ref(`/serviceProvider/${user1.uid}/moneyCollector/customers`)
    .push(customerSelected)
    .then(() => {
      console.log("Data set.moneyCollector cutomer added");
      checkdubArray = [];
    });

Where push id acts as key for customerSelected and I try to get same result in firebase 9. Dont want the result which I have marked as cross其中 push id 作为customerSelected的键,我尝试在 firebase 9 中获得相同的结果。不想要我标记为交叉的结果

You can pass the string value directly in push() along with the DatabaseReference as shown below:您可以将字符串值与DatabaseReference一起直接在push()中传递,如下所示:

const customerSelectedRef = ref(db,`/service/${user1.uid}/Collector/customers`);

await push(customerSelectedRef , "string_value") // Not object

The result would be:结果将是:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Firebase 的不同环境之间推送代码? - How do I push code between different environments in Firebase? 如何使用 Firebase 调试 iOS 的推送通知 - how do I debug push notifications for iOS with Firebase 如何使用 firebase 云消息和云功能设置推送通知? - How can I go about setting up push notifications using firebase cloud messaging and cloud functions? 如何使用谷歌 firebase 发送移动推送通知 - how to send mobile push notification using google firebase 如何在 Firebase 中获取按键? - How to get push key in firebase? 如何在 firebase rtdb 的评论中使用用户 ID 找到相应的用户 - How do i find corresponding user using the userid in reviews in firebase rtdb 使用Firebase Cloud Messaging 的RemoteMessage 时如何指定收件人令牌? - How do I specify the recipient token when using RemoteMessage of Firebase Cloud Messaging? 如何使用 Firebase 在 Flutter 中进行电话身份验证? - How to do Phone Authentication in Flutter using Firebase? 如果我使用 `.push();` 创建一个新的空 Firebase 实时数据库数据,我是否必须在写入之前解析 promise? - If I use `.push();` to crate a new empty Firebase realtime DB datum, do I have to resolve the promise before writing to it? 如何为推送通知注册 Google Classroom API? - How do I register Google Classroom API for push notifications?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM