How do I update data inside documents without specifying the document ID?

拈花ヽ惹草 提交于 2020-04-07 08:07:12

问题


Is there a way to update data inside documents without specifying the document ID,

But while going thorugh stackoverflow I saw this code

firebase.firestore().collection("users")
  .where("name", "==", "Daniel")
  .get(function(querySnapshot) {
    querySnapshot.forEach(function(document) {
     document.ref.update({ ... }); 
    });
  });

Can someone please translate this to flutter code(Dart) please. It's a query to norrow down the document search without having to put in the document ID. I think.


回答1:


The Dart equivalent to code you posted would look like this:

Firestore.instance.collection('users')
  .where('name', isEqualTo: 'Daniel')
  .getDocuments()
  .then((querySnapshot) {
    querySnapshot.documents.forEach((documentSnapshot) {
      documentSnapshot.reference.update({ ... });
    });
  });


来源:https://stackoverflow.com/questions/59144744/how-do-i-update-data-inside-documents-without-specifying-the-document-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!