GVKun编程网logo

SWIFT Firestore 通过查询来获取数据以过滤 whereField is equalTo a autoID 失败

1

在这篇文章中,我们将为您详细介绍SWIFTFirestore通过查询来获取数据以过滤whereFieldisequalToaautoID失败的内容。此外,我们还会涉及一些关于@firebase/fir

在这篇文章中,我们将为您详细介绍SWIFT Firestore 通过查询来获取数据以过滤 whereField is equalTo a autoID 失败的内容。此外,我们还会涉及一些关于@firebase/firestore: Firestore (8.6.2): 无法访问 Cloud Firestore 后端 (React Js)、@firebase/firestore:Firestore (8.3.3):无法访问 Cloud Firestore 后端、@firebase/firestore:Firestore (8.6.5):无法访问 Cloud Firestore 后端、Android Firebase:使用 equalTo 过滤并同时按不同的孩子排序的知识,以帮助您更全面地了解这个主题。

本文目录一览:

SWIFT Firestore 通过查询来获取数据以过滤 whereField is equalTo a autoID 失败

SWIFT Firestore 通过查询来获取数据以过滤 whereField is equalTo a autoID 失败

如何解决SWIFT Firestore 通过查询来获取数据以过滤 whereField is equalTo a autoID 失败

我想通过获取具有相同 bizId 字段的帖子来获取 biz 下的帖子。 我已将所有帖子数据存储在 collection(posts)-> document(autoId) -> ...其中一个字段是 "bId": bizId // biz 数据的 bizId。

并且我已经将所有 Biz 数据存储在 collection(bizs) -> document(autoId)

假设我在 Biz ViewController 并且我想在 collectionViewCell 中获取此 Biz 下的所有帖子。我想使用 (whereField("bId",isEqualTo: bizId) 从帖子池中获取与此 biz 关联的帖子。我收到错误。我只通过以下方式获取数据输出:

  1. static func fetchPostFromBiz(forBiz: String,completion: @escaping ([Post]) -> Void) {
  2. let query = POST_REF.order(by: "ts",descending: true) // where ts is timestamp,if I add limit(to: 16) or whereField("bId",isEqualTo: forBiz) It fails to fetch
  3. query.getDocuments { (snapshot,error) in
  4. if let err = error {
  5. print("error getting doc \\(err)")
  6. } else {
  7. guard let docs = snapshot?.documents else {
  8. print("no doc exist showing empty cell")
  9. return}
  10. let posts = docs.map({Post(dateId: $0.documentID,dictionary: $0.data()) })
  11. completion(posts)
  12. }
  13. }
  14. }

当我申请时 (whereField("bId",isEqualTo: bizId),我收到 [] no dataOutput。 当我申请 (whereF...Id).order(by:...).limit(to:...) 时,我收到需要索引的错误。

解决方法

在您的代码中,您有以下查询:

  1. let query = POST_REF.order(by: "ts",descending: true) // where ts is timestamp,if I add limit(to: 16) or whereField("bId",isEqualTo: forBiz) It fails to fetch

当您尝试组合使用多个查询运算符或混合使用集合时,您会得到复合查询,根据 documentation 这需要必须由用户创建的新索引。

Cloud Firestore 通过要求索引来确保查询性能 每个查询。最基本的查询所需的索引是 自动为您创建。在您使用和测试应用程序时,Cloud Firestore 会生成错误消息,帮助您创建额外的 为您的应用编制索引。

至于这个 (whereField("bId",isEqualTo: bizId) 不接收数据输出,语法在技术上是正确的,它不会返回数据的唯一原因是因为使用该值找不到数据或 bizId 不保存该值您所期望的,在这种情况下,我建议您使用 Analytics SDK 记录数据,使用事件记录器您可以在检测到某些事件时在时间图中可视化并过滤这些以查找您的应用程序中的特定详细信息或错误,{{3} } 是更多关于日志的数据,

citiesRef.whereField("state",isEqualTo: "CA") 这样的单字段查询应该没有索引问题,但您也可以为此创建索引。

@firebase/firestore: Firestore (8.6.2): 无法访问 Cloud Firestore 后端 (React Js)

@firebase/firestore: Firestore (8.6.2): 无法访问 Cloud Firestore 后端 (React Js)

如何解决@firebase/firestore: Firestore (8.6.2): 无法访问 Cloud Firestore 后端 (React Js)

我正在尝试将我的 react js 应用程序与 Firebase Firestore 连接,但出现以下错误,如图 error image 我在集合中有 2 个文档,但我得到一个空的您可以在控制台中看到的数组。这是我用来获取 firestore 数据的代码

const snapshot = await firebase.firestore().collection(''users'').get();
const data = snapshot.docs.map((doc) => doc.data());
console.log(data);

PS:我可以正确使用来自 firebase 的 auth 功能,但在使用 firestore 时出现错误。

到目前为止我尝试过的解决方案:

  1. 同步时钟
  2. 验证了 firebase 规则并确保允许读写(附上我在 firestore 规则部分找到的规则)
rules_version = ''2'';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read,write: if 
          request.time < timestamp.date(2021,6,23);     
    }
  }
}

自从昨晚以来我一直在努力寻找一些快速的解决方案。提前致谢。

解决方法

我尝试了以下步骤来确认 React 应用程序或浏览器存在问题并修复了问题。

  • 尝试使用 node 和 express 获取数据并将数据发布到 Firestore 脚本(这有助于发现问题不在于 firebase 配置)

  • 经过一些在线研究后,我尝试将浏览器从 Brave 更改为 真正有效的 Chrome。

,

屏幕截图中的第一个错误暗示这实际上是一个 Access-Control-Allow-Origin CORS 问题。因此,为了像您在 this article 中看到的那样修复它,您可以:

  • "proxy": "http://localhost:PORT_YOU_ARE_USING" 选项添加到您的 package.json 文件中;

  • 使用像 http-proxy-middleware 这样的中间件来代理请求,您可以按照文章中的示例进行操作。

您还可以查看此 community question,它与您的问题类似,并提供了一些其他解决方案。通过查看,您可能会更好地了解 React 中的 cors 问题。

@firebase/firestore:Firestore (8.3.3):无法访问 Cloud Firestore 后端

@firebase/firestore:Firestore (8.3.3):无法访问 Cloud Firestore 后端

如何解决@firebase/firestore:Firestore (8.3.3):无法访问 Cloud Firestore 后端

在添加了 eslint 并且没有更改代码之后,我运行了我昨天运行良好的应用程序。我最终收到以下错误:

[2021-04-09T04:47:33.960Z]  @firebase/firestore: Firestore (8.3.3): Could not reach Cloud Firestore backend. Connection Failed 1 times. Most recent error: FirebaseError: [code=invalid-argument]: 3 INVALID_ARGUMENT: Invalid resource field value in the request.
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.

我也看到了一些其他的 stackoverflow 帖子和 github 问题,而且大多数人以前似乎也遇到过同样的问题。我尝试了一些建议的解决方案 - 降级 Firebase、检查我的互联网等 - 似乎没有任何效果。

@firebase/firestore:Firestore (8.6.5):无法访问 Cloud Firestore 后端

@firebase/firestore:Firestore (8.6.5):无法访问 Cloud Firestore 后端

如何解决@firebase/firestore:Firestore (8.6.5):无法访问 Cloud Firestore 后端

我之前使用过 expo,但我退出了我的项目,一切正常,除了我的 firebase 连接。它说:@firebase/firestore: Firestore (8.6.5): 无法访问 Cloud Firestore 后端。后端没有在 10 秒内响应。

  1. import firebase from ''firebase'';
  2. import ''@firebase/firestore'';
  3. const firebaseApp = firebase.initializeApp({
  4. apiKey: ''AIzaSyALTdavPNQReVJNWyc2aF8DfexzxzDoXB0'',authDomain: ''projetofinal-e1147.firebaseapp.com'',projectId: ''projetofinal-e1147'',storageBucket: ''projetofinal-e1147.appspot.com'',messagingSenderId: ''546669005614'',appId: ''1:546669005614:web:1b06c375565e04b4c888bf'',measurementId: ''G-KLJBEWBR3S'',});
  5. class Fire {
  6. constructor(callback) {
  7. this.init(callback);
  8. }
  9. init(callback) {
  10. if (!firebase.apps.length) {
  11. firebase.initializeApp(firebaseConfig);
  12. }
  13. firebase.auth().onAuthStateChanged(user => {
  14. if (user) {
  15. callback(null,user);
  16. } else {
  17. firebase
  18. .auth()
  19. .signInAnonymously()
  20. .catch(error => {
  21. callback(error);
  22. });
  23. }
  24. });
  25. }
  26. getLists(callback) {
  27. let ref = this.ref.orderBy(''color'');
  28. this.unsubscribe = ref.onSnapshot(snapshot => {
  29. lists = [];
  30. snapshot.forEach(doc => {
  31. lists.push({id: doc.id,...doc.data()});
  32. });
  33. callback(lists);
  34. });
  35. }
  36. addList(list) {
  37. let ref = this.ref;
  38. ref.add(list);
  39. }
  40. deleteList(list) {
  41. let ref = this.ref;
  42. ref.doc(list.id).delete();
  43. }
  44. updateList(list) {
  45. let ref = this.ref;
  46. ref.doc(list.id).update(list);
  47. }
  48. get userId() {
  49. return firebase.auth().currentUser.uid;
  50. }
  51. get ref() {
  52. return firebase
  53. .firestore()
  54. .collection(''users'')
  55. .doc(this.userId)
  56. .collection(''lists'');
  57. }
  58. detach() {
  59. this.unsubscribe();
  60. }
  61. }
  62. export default Fire;

这是我的 Firebase 文件,它在我的 expo 应用程序中工作,但不再是了。

解决方法

添加:

  1. if (!firebase.apps.length) {
  2. firebase.initializeApp(firebaseConfig);
  3. + firebase.firestore().settings({ experimentalForceLongPolling: true,merge: true });
  4. }

Android Firebase:使用 equalTo 过滤并同时按不同的孩子排序

Android Firebase:使用 equalTo 过滤并同时按不同的孩子排序

如何解决Android Firebase:使用 equalTo 过滤并同时按不同的孩子排序

我有用户发布的帖子,我想以正确的顺序(按发布时间)获取一位用户的所有帖子。

所以我需要这样的东西:

  1. Query query = reference
  2. .child("Posts")
  3. .orderByChild("user_id")
  4. .equalTo(given_user_id)
  5. .orderByChild("negative_timestamp");

但这不起作用,因为 Firebase 只允许在查询中调用一次 orderByChild()

如何解决这个问题?

今天的关于SWIFT Firestore 通过查询来获取数据以过滤 whereField is equalTo a autoID 失败的分享已经结束,谢谢您的关注,如果想了解更多关于@firebase/firestore: Firestore (8.6.2): 无法访问 Cloud Firestore 后端 (React Js)、@firebase/firestore:Firestore (8.3.3):无法访问 Cloud Firestore 后端、@firebase/firestore:Firestore (8.6.5):无法访问 Cloud Firestore 后端、Android Firebase:使用 equalTo 过滤并同时按不同的孩子排序的相关知识,请在本站进行查询。

本文标签: