...FirebaseFirestoreException:无法使用 EddyVerbruggen / nativescript-plugin-firebase 从服务器获取文档

问题描述

修复:我搞砸了安装,使用了旧版本的库, 第二次安装它解决了我的问题。

我在 Android 上的 Nativescript 7 Angular 应用程序中使用 firebase 时遇到问题。 我尝试按照此处的文档进行操作: https://github.com/EddyVerbruggen/nativescript-plugin-firebase 在这里https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/master/docs/FIRESTORE.md

我通过控制台创建了 firestore,如下所示: [我的 firebase 的屏幕截图][1] [1]:https://i.stack.imgur.com/G5a37.png 我添加了 google-services json,然后尝试像这样使用它: 在 app-component.ts 中:

import { firebase } from "@nativescript/firebase";
/* ... */

@Component({
    selector: "ns-app",templateUrl: "app.component.html"
})
export class AppComponent implements OnInit {
    constructor() { }

    ngOnInit(): void { 
        firebase.init()
          .then(
            () => {
              console.log("firebase.init done");
            },error => {
              console.log(`firebase.init error: ${error}`);
            }
          );
    }

    /* ... */

这很好用,我收到消息“firebase.init done” 但是后来我尝试在不同的组件中使用 firestore 来测试这样的事情:

import * as firebase from "@nativescript/firebase/app";

@Component({
    templateUrl: "./message-list.component.html",styleUrls: ["./message-list.component.scss"],})
export class MessageListComponent implements OnInit {
    userNameCollection;
 
    constructor(private service: MessagesService,private router: Router) {

        this.userNameCollection = firebase.firestore().collection("testUsernames");
        this.userNameCollection.get({ source: "server" }).then((querySnapshot) => {
            querySnapshot.forEach((doc) => {
                console.log("something exists");
                console.log(`${doc.id} => ${JSON.stringify(doc.data())}`);
            });
        }).catch(error=>console.log("error: "+error));
    }
    
    /* ... */

这里,我得到错误

错误:com.google.firebase.firestore.FirebaseFirestoreException:无法从服务器获取文档。 (但是,这些文档可能存在于本地缓存中。再次运行,不要将源设置为 SERVER 以检索缓存的文档。)

如果没有将源设置到服务器,我不会收到错误消息,但也不会收到 console.log() 结果或“存在某物”消息。

我将 Firestore 设置为测试模式,因此我的规则如下所示:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read,write: if
          request.time < timestamp.date(2021,5,18);
    }
  }
}

在这里做错了什么?/关于此的任何有用的文档或我如何获得有关问题出处的更多信息?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...