简体   繁体   English

如何在 Cloud Firestore 中编辑文档中的密钥对?

[英]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.

相关问题 Firestore - 如何将新的键值对添加到包含地图列表的文档中? - Firestore - How do I add a new key value pair to a document containing a list of maps? 如何使用模块 Web SDK 的版本 9 在 Cloud Firestore 集合中的文档中获取文档和嵌套集合? - How do I get document and nested collection in a document in a Cloud Firestore collection using Version 9 of the Modular Web SDK? 如何使用 StreamBuilder 显示我的 Cloud firestore 数据库中一个特定文档的数据? - How do I use StreamBuilder to display the data from ONE specific document in my Cloud firestore database? 如何使用帮助文档 ID 更新 Cloud firestore 文档字段? - How can i Update Cloud firestore document Field with the help DocumentID? 如何从 firestore 文档中检索密钥(使用 swift 4/ios) - How do I retrieve a key from a firestore document (using swift 4/ios) 如何在 Firestore 中获取文档密钥 - How to get document key in Firestore 如何使用 Cloud firestore 中的文档 ID 访问文档字段? - How can I acess a document field using document id from cloud firestore? 如何在 Cloud Firestore 文档中列出子集合 - How to list subcollections in a Cloud Firestore document 如何从云功能中的 firestore 获取文档 - How to get a document from firestore in cloud functions 如何删除 Google Cloud Firestore 中项目的所有 collections? - How do I delete ALL collections for a project in Google Cloud Firestore?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM