[英]How do I edit a key pair in a document in Cloud Firestore?
I want to edit the following key pair in Cloud Firestore:我想在 Cloud Firestore 中编辑以下密钥对:
For this I created a button that calls the following function:为此,我创建了一个调用以下 function 的按钮:
void select(key) {
if (key == 'Stufe 1') {
stufenService.editStufe('Stufe', 1);
}
if (key == 'Stufe 2') {
stufenService.editStufe('Stufe', 2);
}
if (key == 'Stufe 3') {
stufenService.editStufe('Stufe', 3);
}
if (key == 'Stufe 4') {
stufenService.editStufe('Stufe', 4);
}
if (key == 'Stufe 5') {
stufenService.editStufe('Stufe', 5);
}
if (key == 'Stufe 6') {
stufenService.editStufe('Stufe', 6);
} print(key);
}
This is the exact code of stufenService.editStufe(String, int):这是 stufenService.editStufe(String, int) 的确切代码:
final CollectionReference userTodos =
FirebaseFirestore.instance.collection('userTodos');
Future editStufe(String Stufe, int i) async{
return await userTodos.doc(userID).update({Stufe: i});
}
}
When I press the button that calls 'select', only the key is printed in the console.当我按下调用“选择”的按钮时,控制台中只打印出该键。 Nothing changes in Cloud Firestore.
Cloud Firestore 中没有任何变化。 I think the mistake is somewhere here:
我认为错误就在这里:
final CollectionReference userTodos =
FirebaseFirestore.instance.collection('userTodos');
Future editStufe(String Stufe, int i) async{
return await userTodos.doc(userID).update({Stufe: i});
}
}
I hope I have provided all the necessary data so that the problem can be solved.我希望我已经提供了所有必要的数据,以便可以解决问题。 If not, just write it to me and I will try to send you the material you need.
如果没有,请写信给我,我会尽力将您需要的材料发送给您。
While reviewing google and external documentation, you could use the following code example to update your key pair on Cloud Firestore
:在查看 google 和外部文档时,您可以使用以下代码示例更新
Cloud Firestore
上的密钥对:
This is an example code of how to update your key pair using ' update
':这是如何使用“
update
”更新密钥对的示例代码:
const usuariosRef = db.collection(‘userTodos’);
//userTodosRef.doc(‘ID’)
userTodosRef
.doc(‘81Acc0wgLegYMSTTrCWLRQhzjA2’)
.update({
stufe = 1
});
This is an example code of how to update your key pair using ‘`set`’:
const usuariosRef = db.collection(‘userTodos’);
//userTodosRef.doc(‘ID’)
userTodosRef
.doc(‘81Acc0wgLegYMSTTrCWLRQhzjA2’)
.set({
stufe = 1
});
The difference between both is that 'update' only changes the value you want to update, 'set' deletes all the data and updates it with the value added.两者之间的区别在于“更新”仅更改您要更新的值,“设置”删除所有数据并使用添加的值更新它。
Here is a document that could help you with references you can performed with your data: https://googleapis.dev/nodejs/firestore/latest/DocumentReference.html#update这是一份文档,可以帮助您参考您的数据: https://googleapis.dev/nodejs/firestore/latest/DocumentReference.html#update
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.