我如何在不指定文档ID的情况下更新文档内部的数据?

问题描述 投票:0回答:1

是否可以在不指定文档ID的情况下更新文档内部的数据,

但是在通过thostackh stackoverflow时,我看到了此代码

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

有人可以将其翻译为颤动代码(Dart)吗?这是一个查询,用于在不输入文档ID的情况下向下搜索文档搜索。我认为。

firebase flutter dart google-cloud-firestore
1个回答
1
投票

相当于您发布的代码的Dart看起来像这样:

Firestore.instance.collection('users')
  .where('name', isEqualTo: 'Daniel')
  .getDocuments()
  .then((querySnapshot) {
    querySnapshot.documents.forEach((documentSnapshot) {
      documentSnapshot.reference.update({ ... });
    });
  });
© www.soinside.com 2019 - 2024. All rights reserved.