云函数正在将 NaN 写入 firestore

2024-07-03

我创建了一个云函数来在每次有新关注者时更新关注计数。然而,无论出于何种原因,NaN被写入文档而不是递增计数。什么是NaN为什么写的是它而不是适当的数字?这是我的代码:

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 is 不是一个数字 https://en.wikipedia.org/wiki/NaN。正如一些评论者所说(但没有实际发布答案),这是由对非数字输入的操作引起的,例如未定义的值或字符串。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

云函数正在将 NaN 写入 firestore 的相关文章

随机推荐