繁体   English   中英

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

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

我正在构建一个使用 Firebase Cloud Firestore 数据库的 React Native 应用程序。 我已经实现了多个快照侦听器来获取不同的 collections。 但是,我遇到了以下错误[Unhandled promise rejection: FirebaseError: Quota exceeded.]

我检查了我的代码并返回到开发人员文档,但我无法找到问题所在。 我怀疑问题可能出在getCompetitionCollectionListener上。

如何在我的代码中找到错误的确切原因以及如何实施修复? 我是否可能错误地编写了异步调用 function 或在某处遗漏了一行代码?

数据库功能:

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);
};

错误信息:

[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_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if
          request.time < timestamp.date(2022, 12, 12);
    }
  }
}

使用截图: Firestore Usage Quota Exceeded 截图

我相信当您超出配额限制时会引发此错误。

看看https://firebase.google.com/docs/firestore/quotas

将 try catch 添加到您的函数中,这样您就可以知道哪个引发了此错误并采取相应措施

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM