Firebase Firestore增量FieldValue不增量 [英] Firebase Firestore Increment FieldValue does not increment

查看:78
本文介绍了Firebase Firestore增量FieldValue不增量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我已经阅读了所有文档,有关在Firestore数据库中增加计数器的所有内容. 我有此代码

so i've read all the documentation everything about increment a counter in a Firestore database. I have this code

const admin = require("firebase-admin");
const db = admin.firestore();
...
db
.collection("settings")
.doc("totalUsers")
.set({
count: firebase.firestore.FieldValue.increment(1),
});

我只是根本不增加计数器.没有错误,没有日志,什么都没有. 在我的Firestore中,我有一个settings的集合和一个具有属性count的文档totalUsers,该属性是数字类型,等于1.

And i just doesn't increment the counter at all. No errors no logs no nothing. In my Firestore i have a collection of settings and a document totalUsers with a property count that is a number type and it equals to 1.

我做错什么了吗? 我有什么想念的吗? 任何帮助表示赞赏!

Am I doing something wrong? Am I missing anything? Any help appreciated!

推荐答案

对于任何对此有疑问的人,请小心使用.update()方法代替.set().另外,您还需要在Firestore中存在一个值,以便它可以增加一些值.

For anyone having issues with this, be careful to use the .update() method instead .set(). Also you need to have a value existing in the firestore that so it has something to increment.

这篇关于Firebase Firestore增量FieldValue不增量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆