微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决...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.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?