firebase - ...FirebaseFirestoreException:无法使用 EddyVerbruggen / nativescript-plugin-firebase 从服务器获取文档
问题描述
修复:我搞砸了安装并且使用了旧版本的库,第二次安装它解决了我的问题。
我在 Android 上将 Firebase 与我的 Nativescript 7 Angular 应用程序一起使用时遇到了问题。我尝试遵循此处的文档: 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 完成”但后来我尝试在不同的组件中使用 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);
}
}
}
我在这里做错了什么?/关于此的任何有用的文档或我如何获得有关问题出处的更多信息?
解决方案
推荐阅读
- python - 上传视频和缩略图 - YouTube Data API Python
- r - 使用 Rselenium 从下拉菜单中获取值
- flutter - 在颤动中访问提供程序设置器时不存在获取函数返回错误
- html - 在 iframe 中隐藏垂直滚动
- amazon-sqs - 带有 stepfunction 的 FIFO 主题需要 MessageGroupId 参数
- java - android套接字在模拟器上工作,但在我的真实设备上不工作
- python - 即使存在依赖项,也安装缺少的依赖项?
- c++ - C++ find_if 导致绑定函数崩溃
- postgresql - 为什么 psql 中没有添加此列?
- java - Java如何将对象作为参数从类传递给另一个类