[英]how to update info in firebase version 9
I would like besides add new record, also change 'bill'.我想除了添加新记录外,还要更改“账单”。 But I don't know what input in this string
但我不知道这个字符串中的输入是什么
const newPostKey = (child(ref(db), )).key;
This action in vuex, that I use for create request to firebase: vuex 中的此操作,我用于创建对 firebase 的请求:
async updateInfo({ dispatch, commit, getters }, toUpdate) {
try {
const uid = await dispatch('getUid')
const db = getDatabase();
const updateData = { ...getters.info, ...toUpdate }
const postListRef = ref(db, `/users/${uid}/info`);
const newPostKey = (child(ref(db), ????)).key;
const updates = {};
updates[newPostKey] = updateData;
update(postListRef, updates)
commit('setInfo', updateData)
} catch (e) {
commit('setError', e)
throw e
}
},
Code work up to step const newPostKey..代码工作到步骤 const newPostKey..
If I input in this string 'info':如果我输入这个字符串“信息”:
const newPostKey = (child(ref(db), 'info')).key;
Record will be added, but 'info' will be update incorrect:将添加记录,但“信息”将更新不正确:
If you just want to update the value of bill
then you can try the following:如果您只想更新
bill
的价值,那么您可以尝试以下操作:
const userRef = ref(db, `/users/${uid}/info`);
update(userRef, { bill: 100 }).then(() => { // <-- replace 100 with your bill amount
console.log("Bill Amount Updated")
}).catch(e => console.log(e))
If you want to increment the bill by a certain amount, you can do so using increment()
function.如果您想将账单增加一定数量,可以使用
increment()
function 来实现。
update(userRef, { bill: increment(100) }) // increment by 100
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.