Cloud function is writing NaN to firestore

泪湿孤枕 提交于 2019-12-14 03:57:29

问题


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);
});

回答1:


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.



来源:https://stackoverflow.com/questions/48797377/cloud-function-is-writing-nan-to-firestore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!