如何将childNode从一个节点复制到另一个节点?

Cod*_*000 7 javascript node.js firebase firebase-realtime-database

情况:

我需要下载childNode,然后将()设置为另一个节点.

问题是我想在childNode的得分属性达到100时才这样做.

我应该在何时何地检查帖子的分数是否为100或更高,以及如何仅将其复制到新索引一次?


我的想法是什么:

加载帖子后,检查其分数.如果> = 100,请检查数据库是否属于这种情况.然后将节点推送到新索引.


问题:

每次加载帖子时,如何阻止节点上传,因为多次加载时得分> = 100?我需要它只发生一次!


解决方案代码:

if (funPost.score >= global.hotNumber && funPost.hot == false) {
            var hotPostRef = firebase.database().ref("hot/section/"+key);
            var hotPost = {
                title: funPost.title,
                image: funPost.image,
                id: funPost.id,
                key: funPost.key
            }
            hotPostRef.set(hotPost);
            funPostRef.update({"hot": true});
        }
   else if (funPost.score <= (global.hotNumber - 25) && funPost.hot == true) {
        var hotPostRef = firebase.database().ref("hot/section/"+key);
        hotPostRef.remove();
        funPostRef.update({"hot": false});
   }
Run Code Online (Sandbox Code Playgroud)

解决方案:我最终使用了布尔标志.

Cod*_*000 1

我最终用一个布尔标志来做到这一点:

if (funPost.score >= global.hotNumber && funPost.hot == false) {
            var hotPostRef = firebase.database().ref("hot/section/"+key);
            var hotPost = {
                title: funPost.title,
                image: funPost.image,
                id: funPost.id,
                key: funPost.key
            }
            hotPostRef.set(hotPost);
            funPostRef.update({"hot": true});
        }
   else if (funPost.score <= (global.hotNumber - 25) && funPost.hot == true) {
        var hotPostRef = firebase.database().ref("hot/section/"+key);
        hotPostRef.remove();
        funPostRef.update({"hot": false});
   }
Run Code Online (Sandbox Code Playgroud)