gpt4 book ai didi

javascript - Firestore 设置功能不起作用

转载 作者:行者123 更新时间:2023-11-30 20:49:17 25 4
gpt4 key购买 nike

我正在尝试使用云功能将我的所有帖子移动到 firestore

exports.copyPosts = functions.https.onRequest((req, res) => {
var i = 0;
var username;
db.ref("feeds").child("all").limitToLast(2000).once("value", function (postSnap) {
console.log(postSnap.numChildren());

postSnap.forEach(function(topic){
i = i + 1;


firestore.collection("topics").doc(i+"").set({
caption: topic.child("caption").val(),
time: topic.child("time").val(),
username: topic.child("username").val(),
category: topic.child("category").val(),
pic: topic.child("pic").val()

})

if(postSnap.numChildren()==i){
res.contentType('application/json');
res.status(200).send("Success");
}
});
});

});

它返回成功。在此之前,我使用这个循环将帖子复制到另一个实时数据库位置并且它起作用了。

但是对于 firestore 没有添加任何数据并且日志中没有错误显示..

最佳答案

我可以使用云功能将数据插入到 firestore。您可以先将数据传递给变量,然后将变量放入 set() 操作中。希望对你有帮助

exports.insertDB = functions.https.onRequest((request,response) =>
{
var firstname_input = request.query.name;
db.collection("user").doc(firstname_input).set({
first_name : firstname_input,
last_name : "Chow",
hobby : "Swimming"
})
response.send("Inserted a new user, name: " + firstname_input);
});

关于javascript - Firestore 设置功能不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48360490/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com