Firestore first()).toPromise() 总是给出旧值,即使我重新 运行 进行了新更改

Firestore first()).toPromise() always gives old value even I have re-run with new changes

我在服务上有这个方法:

     getUserLink(uid: string): Promise<ConnectionLinkModel> {
            return this.afs.doc<ConnectionLinkModel>
(`userConnectionLinks/${uid}`).valueChanges().pipe(first()).toPromise();
        }

这是第一次运行良好。但是假设我已经手动更改了 Firestore 数据并再次重新 运行 此方法(这非常重要。我知道因为这是承诺它不会自动收听更改。但为什么它不给新值,即使我重新 运行 它再次。)。但它永远不会改变价值。即它总是给出旧值。 我该如何处理这个用例?

    ngOnInit(): void {
        const res: ConnectionLinkModel = await 
this.connectionLinkService.getUserLink(this.authService.currentUserUid);
      }

注意: 当页面再次加载时 运行s。但它永远不会赋予新的价值。为什么?

如果您有 enabled persistence,那么您获得的第一个数据将始终来自本地缓存。

来自docs

To check whether you're receiving data from the server or the cache, use the fromCache property on the SnapshotMetadata in your snapshot event. If fromCache is true, the data came from the cache and might be stale or incomplete. If fromCache is false, the data is complete and current with the latest updates on the server.

 getUserLink(uid: string): Promise<ConnectionLinkModel> {

                return this.afs.doc<ConnectionLinkModel>(`userConnectionLinks/${uid}`)
                                 .valueChanges()
                                 .pipe(debounceTime(1000)).pipe(first()).toPromise();
            }