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