Afs*_*ara 3 javascript firebase react-native google-cloud-firestore
我们正在尝试使用 react native app 手动添加文档值到 firestore DB。
这是我们为 web 找到的参考代码
db.collection("cities").doc("LA").set({
name: "Los Angeles",
state: "CA",
country: "USA"
})
.then(function() {
console.log("Document successfully written!");
})
.catch(function(error) {
console.error("Error writing document: ", error);
});
Run Code Online (Sandbox Code Playgroud)
对于本机反应,我们使用了此代码
firebase.firestore().collection('users').doc("hello").add({
title: this.state.textInput,
complete: false,
})
Run Code Online (Sandbox Code Playgroud)
我收到错误,例如添加我们未定义
如何向其中添加文档和集合?
在这里我找到了我的数据结构的解决方案
firebase
.firestore()
.collection("Users")
.doc("mydoc")
.collection("Activities")
.doc("Database")
.set({
key: "1",
value: "",
})
.then((ref) => { console.log(ref) });
Run Code Online (Sandbox Code Playgroud)
您可以将文档添加到集合中。您不能将文档添加到文档。
要将文档添加到您的users集合:
firebase.firestore().collection('users').add({
title: this.state.textInput,
complete: false,
})
Run Code Online (Sandbox Code Playgroud)
所以.doc("hello")从那里删除。
| 归档时间: |
|
| 查看次数: |
7190 次 |
| 最近记录: |