云功能正在将NaN写入Firestore [英] Cloud function is writing NaN to firestore

查看:55
本文介绍了云功能正在将NaN写入Firestore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个cloud Function,以在每次有新关注者时更新关注计数.但是,无论出于何种原因,NaN都会被写入文档中,而不是增加计数.什么是NaN?为什么要写它而不是适当的数字?这是我的代码:

I created a cloud Function to update a following count every time there is a new follower. However, for whatever reason, NaN gets written to the document instead of an incremented count. What is NaN and why is it getting written instead of the appropriate number? This is my code:

var transaction = db.runTransaction(t => {
    return t.get(countRef)
        .then(doc => {
            var new_count = doc.data.following_count + 1;
            t.update(countRef, { following_count: new_count });
        });
}).then(result => {
    console.log('Transaction success!');
})
.catch(err => {
    console.log('Transaction failure:', err);
});

推荐答案

NaN是 不是数字 .正如一些评论者所说(但没有实际发布答案),这是由对非数字输入的操作(例如未定义的值或字符串)引起的.

NaN is Not a Number. As some commenters said (but without actually posting an answer), this is caused by operations on non-numeric input, such as undefined values or strings.

这篇关于云功能正在将NaN写入Firestore的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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