What's the best way to check if a Firestore record exists if its path is known?

前端 未结 6 1643
野性不改
野性不改 2020-12-28 15:15

Given a given Firestore path what\'s the easiest and most elegant way to check if that record exists or not short of creating a document observable and subscribing to it?

6条回答
  •  臣服心动
    2020-12-28 15:57

    If for whatever reason you wanted to use an observable and rxjs in angular instead of a promise:

    this.afs.doc('cities', "SF")
    .valueChanges()
    .pipe(
      take(1),
      tap((doc: any) => {
      if (doc) {
        console.log("exists");
        return;
      }
      console.log("nope")
    }));
    

提交回复
热议问题