相关疑难解决方法(0)

Flutter firestore - 检查文档 ID 是否已存在

如果文档 ID 不存在,我想将数据添加到 Firestore 数据库中。到目前为止我尝试过的:

// varuId == the ID that is set to the document when created


var firestore = Firestore.instance;

if (firestore.collection("posts").document().documentID == varuId) {
                      return AlertDialog(
                        content: Text("Object already exist"),
                        actions: <Widget>[
                          FlatButton(
                            child: Text("OK"),
                            onPressed: () {}
                          )
                        ],
                      );
                    } else {
                      Navigator.of(context).pop();
                      //Adds data to the function creating the document
                      crudObj.addData({ 
                        'Vara': this.vara,
                        'Utgångsdatum': this.bastFore,
                      }, this.varuId).catchError((e) {
                        print(e);
                      });
                    }
Run Code Online (Sandbox Code Playgroud)

目标是检查数据库中的所有文档 ID,并查看与“varuId”变量的任何匹配项。如果匹配,则不会创建文档。如果不匹配,它应该创建一个新文档

dart firebase flutter google-cloud-firestore

8
推荐指数
4
解决办法
1万
查看次数

flutter / dart 如何检查firestore中是否存在文档?

我尝试使用 bool 查询 cloudfirestore 上是否存在文档。不幸的是,我的代码不起作用

我尝试了以下操作,但 bool 没有改变。

getok() {
  bool ok;
  Firestore.instance.document('collection/$name').get().then((onexist){
      onexist.exists ? ok = true : ok = false;
    }
  ); 
  if (ok = true) {
    print('exist');
  } else {
    print('Error');
  }
}
Run Code Online (Sandbox Code Playgroud)

dart firebase flutter google-cloud-firestore

3
推荐指数
3
解决办法
9385
查看次数

标签 统计

dart ×2

firebase ×2

flutter ×2

google-cloud-firestore ×2