颤振|如何将数据添加到Firestore中的现有文档 [英] FLUTTER | How to add data to an existing document in firestore
本文介绍了颤振|如何将数据添加到Firestore中的现有文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用firestore存储我的flutter应用程序的数据,并且我创建了一个函数,该功能可以在用户登录
后自动在firestore中创建一个文档我的Firestore数据库
I'm using firestore to store data of my flutter application, and I made a function that creates a document in firestore automatically after the user login My Firestore database
现在,我希望用户在填写此表单时将其数据添加到用户电子邮件所在的同一文档中。
Now I want the user when he fills this form , the data will be added in the same document where the user's email exists.
[ RaisedButton(
child: Text("Submit"),
onPressed: () {
final CollectionReference users = Firestore.instance.collection('users');
Firestore.instance
.runTransaction((Transaction transaction) async {
CollectionReference reference =
Firestore.instance.collection('users');
await reference
.add({"fullname": nameController.text, "PhoneNumber": phoneController.text, "adresse": adressController.text});
nameController.clear();
phoneController.clear();
adressController.clear();
});},][2]
我尝试了此代码
推荐答案
在更新数据库之前指定文档名称。
Specify document name before updating database.
Firestore.instance
.collection('Products')
.document('Apple')
.updateData({
'price': 120,
'quantity': 15
});
这里我的价格和数量数据是数字。如果您输入的是 String
,则在其中输入 String
值。
Here my price and quantity data are numbers. If yours are String
s put String
values there.
这篇关于颤振|如何将数据添加到Firestore中的现有文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文