admin管理员组文章数量:1415120
I note that there's instructions on how to increment values for realtime database in Javascript v8:
===
Added ServerValue.increment() to support atomic field value increments without transactions.
API Docs here
Usage example:
firebase.database()
.ref('node')
.child('clicks')
.set(firebase.database.ServerValue.increment(1))
Or you can decrement, just put -1 as function arg like so:
firebase.database()
.ref('node')
.child('clicks')
.set(firebase.database.ServerValue.increment(-1))
However, I notice that there isn't any reference to ServerValue in the v9 documentation.
Does this mean that this functionality is not available?
I've tried converting it to v9 on my own but I've been unsuccessful so far:
const setWeekComplete = () => {
set(ref(database, `users/${user}/streakCounter`), {
weeks: database.ServerValue.increment(1)
});
}
I note that there's instructions on how to increment values for realtime database in Javascript v8:
===
Added ServerValue.increment() to support atomic field value increments without transactions.
API Docs here
Usage example:
firebase.database()
.ref('node')
.child('clicks')
.set(firebase.database.ServerValue.increment(1))
Or you can decrement, just put -1 as function arg like so:
firebase.database()
.ref('node')
.child('clicks')
.set(firebase.database.ServerValue.increment(-1))
However, I notice that there isn't any reference to ServerValue in the v9 documentation.
Does this mean that this functionality is not available?
I've tried converting it to v9 on my own but I've been unsuccessful so far:
const setWeekComplete = () => {
set(ref(database, `users/${user}/streakCounter`), {
weeks: database.ServerValue.increment(1)
});
}
Share
Improve this question
edited Nov 20, 2021 at 11:10
Renaud Tarnec
83.2k10 gold badges98 silver badges129 bronze badges
Recognized by Google Cloud Collective
asked Nov 20, 2021 at 10:40
Lloyd RajooLloyd Rajoo
1474 silver badges14 bronze badges
0
1 Answer
Reset to default 8It is still available in V9 and you'll find it here in the doc. So the following should do the trick.
import { ... , increment } from 'firebase/database';
// ...
const setWeekComplete = async () => {
await set(ref(database, `users/${user}/streakCounter`), {
weeks: increment(1)
});
}
本文标签: javascriptHow to increment values in Firebase Realtime Database (v9)Stack Overflow
版权声明:本文标题:javascript - How to increment values in Firebase Realtime Database (v9) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745196553a2647166.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论