[英]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);
}
}
}
我相信當您超出配額限制時會引發此錯誤。
看看https://firebase.google.com/docs/firestore/quotas
將 try catch 添加到您的函數中,這樣您就可以知道哪個引發了此錯誤並采取相應措施
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.