我正在尝试将我在表单中输入的数据设置为 Firebase 中的字段名称。
$("#blogUID").val()它在第 3 行(博客/blogUID 集合)中工作得很好。但是,当我尝试在 Stats/Blogs 集合(第 10 行)中设置字段名称时,出现以下错误:
error.ts:166 Uncaught FirebaseError: Function CollectionReference.doc() requires its first argument to be of type non-empty string, but it was: undefined
at new ui (https://www.gstatic.com/firebasejs/7.17.1/firebase-firestore.js:1:52471)
at Vh (https://www.gstatic.com/firebasejs/7.17.1/firebase-firestore.js:1:164122)
at kh (https://www.gstatic.com/firebasejs/7.17.1/firebase-firestore.js:1:163328)
at _d.doc (https://www.gstatic.com/firebasejs/7.17.1/firebase-firestore.js:1:280502)
at HTMLButtonElement.<anonymous> (http://localhost:8080/TeamSolheim_Page1.html:251:36)
at HTMLButtonElement.dispatch (https://code.jquery.com/jquery-3.5.1.min.js:2:43090)
at HTMLButtonElement.v.handle (https://code.jquery.com/jquery-3.5.1.min.js:2:41074)
1 $("#blog-submit-button").click(function(){
2 // Add a new document in collection
3 // db.collection("Blogs").doc($("#blogUID").val()).set({
4 // blogDate: $("#blogDate").val(),
5 // blogLink: $("#blogLink").val(),
6 // blogTitle: $("#blogTitle").val(),
7 // })
8 // .then(function() {
9 db.collection("Stats").doc($("Blogs").val()).set({
10 $("#blogUID").val(): $("#blogLikes").val(),
11 })
12 .then(function() {
console.log("Document successfully written!");
$("#blog-form").hide();
$("#create-form").show();
})
.catch(function(error) {
console.error("Error writing document 2: ", error);
});
// })
// .catch(function(error) {
// console.error("Error writing document 1: ", error);
// });
})
权限对任何经过身份验证的用户都是开放的:
match /Stats/Blogs {
allow read;
allow write: if request.auth != null;
}
小怪兽爱吃肉
函数式编程
相关分类