简体   繁体   English

快照侦听器中未捕获的错误。 超出 Firebase 配额

[英]Uncaught Error in snapshot listener. Firebase quota exceeded

I'm building a React Native app which makes use of Firebase Cloud Firestore database.我正在构建一个使用 Firebase Cloud Firestore 数据库的 React Native 应用程序。 I have implemented multiple snapshot listeners to fetch the different collections.我已经实现了多个快照侦听器来获取不同的 collections。 However, I've encountered the following error [Unhandled promise rejection: FirebaseError: Quota exceeded.]但是,我遇到了以下错误[Unhandled promise rejection: FirebaseError: Quota exceeded.]

I've checked my code and gone back to the developer docs but I'm not able to find where the problem is.我检查了我的代码并返回到开发人员文档,但我无法找到问题所在。 I suspect the problem could be with the getCompetitionCollectionListener function.我怀疑问题可能出在getCompetitionCollectionListener上。

How do I find the exact cause of the error in my code and how would you implement a fix?如何在我的代码中找到错误的确切原因以及如何实施修复? Did I perhaps write the async call function incorrectly or miss a line of code somewhere?我是否可能错误地编写了异步调用 function 或在某处遗漏了一行代码?

Database Functions:数据库功能:

import { auth, db } from "../config/firebase.config";
import {
  doc,
  setDoc,
  Timestamp,
  collection,
  getDocs,
  addDoc,
  onSnapshot,
} from "firebase/firestore";

//Create a New User Function.
export const createUserOnRegister = (user, username) => {
  const userRef = doc(db, "users", user.uid);
  const userData = {
    email: user.email,
    username: username,
    role: "cosplayer",
    dateCreated: Timestamp.fromDate(new Date()),
  };
  return setDoc(userRef, userData);
};

// Get All Users Function.
export const getAllUsers = async () => {
  const users = [];
  // Query the firestore db for the collection of users
  const querySnapshot = await getDocs(collection(db, "users"));
  // Loop through the users collection and retrieve the uid of each user
  querySnapshot.forEach((doc) => {
    let user = { ...doc.data(), uid: doc.id };
    users.push(user);
  });
  return users;
};

//Create a new competition item in the firestore db.
export const newCompetition = (competition) => {
  return addDoc(collection(db, "competitions"), competition);
};

// Return the collection of competitions from the firestore db.
export const getCompetitionCollectionListener = () => {
  return collection(db, "competitions");
};

// Return the collection of entries.
export const getEntryOfCompetition = async (id) => {
  let entries = [];

  const collectionRef = collection(db, "competitions/" + id + "/entries");
  const collectionSnapshot = await getDocs(collectionRef);

  collectionSnapshot.forEach((doc) => {
    entries.push(doc.data());
  });
  return entries;
};

// Add a new Entry to the Competition collection.
export const addEntryToCompetition = async (data, id) => {
  const collectionRef = collection(db, "competitions/" + id + "/entries");
  // const collectionSnapshot = await addDoc(collectionRef, data);
  return addDoc(collectionRef, data);
};

Error Message:错误信息:

[Unhandled promise rejection: FirebaseError: Quota exceeded.]
at node_modules\@babel\runtime\helpers\construct.js:null in _construct
at node_modules\@babel\runtime\helpers\wrapNativeSuper.js:null in Wrapper
at http://192.168.1.3:19000/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&hot=false&strict=false&minify=false:null in _createSuperInternal
at node_modules\@firebase\util\dist\index.esm2017.js:null in FirebaseError#constructor
at http://192.168.1.3:19000/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&hot=false&strict=false&minify=false:null in _createSuperInternal
at node_modules\@firebase\firestore\dist\index.rn.js:null in j#constructor
at node_modules\@firebase\firestore\dist\index.rn.js:null in Gs
at node_modules\promise\setimmediate\core.js:null in setImmediate$argument_0
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:null in _allocateCallback$argument_0
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:null in _callTimer
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:null in _callReactNativeMicrotasksPass
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:null in callReactNativeMicrotasks
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:null in __callReactNativeMicrotasks
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:null in __guard$argument_0
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:null in __guard
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:null in flushedQueue

Rules:规则:

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

Usage Screenshot: Screenshot of Firestore Usage Quota Exceeded使用截图: Firestore Usage Quota Exceeded 截图

I believe this error is thrown when you exceeded your quota limit.我相信当您超出配额限制时会引发此错误。

Take a look at https://firebase.google.com/docs/firestore/quotas看看https://firebase.google.com/docs/firestore/quotas

Add try catch to your functions so you can know which one is throwing this error and act accordingly将 try catch 添加到您的函数中,这样您就可以知道哪个引发了此错误并采取相应措施

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么收到 Firebase Quota 超出错误? - WHy getting Firebase Quota exceeded error? 未捕获(承诺)DOMException:超出配额 - Uncaught (in promise) DOMException: Quota exceeded 快照侦听器中未捕获的错误:FirebaseError:找不到匹配的索引 - Uncaught Error in snapshot listener: FirebaseError: no matching index found 快照侦听器中未捕获的错误:FirebaseError:缺少权限或权限不足 - Uncaught Error in snapshot listener: FirebaseError: Missing or insufficient permissions 快照侦听器中的未捕获错误:,FirebaseError:[code = permission-denied]:缺少或权限不足 - Uncaught Error in snapshot listener:, FirebaseError: [code=permission-denied]: Missing or insufficient permissions 403:配额错误:批处理请求超出了用户速率限制 - 403: Quota Error: User Rate Limit Exceeded witht Batch Request 在iOS上超过LocalStorage配额(dom错误22),但未设置私有模式 - LocalStorage quota exceeded (dom error 22) on iOS, but private mode not set Chrome API:超过运行时 QUOTA_BYTES_PER_ITEM 配额错误,但预检查通过 - Chrome API: Runtime QUOTA_BYTES_PER_ITEM quota exceeded Error, but precheck passes Uncaught DOMException: Failed to execute 'setItem' on 'Storage': Setting the value of 'domains' exceeded the quota - Uncaught DOMException: Failed to execute 'setItem' on 'Storage': Setting the value of 'domains' exceeded the quota Safari 的 html5 localStorage 错误:“QUOTA_EXCEEDED_ERR:DOM 异常 22:尝试向存储添加超出配额的内容。” - html5 localStorage error with Safari: “QUOTA_EXCEEDED_ERR: DOM Exception 22: An attempt was made to add something to storage that exceeded the quota.”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM