Firestore控制台 - 文档大小限制

时间:2018-04-25 08:54:15

标签: firebase google-cloud-firestore

我想知道Firestore上存储的文档的最大大小是多少?我有一个示例json,我试图将其存储在Firestore中作为文档,但是当我尝试从控制台读取它时,我的Web浏览器会冻结。从查询中读取它没有问题。 文档样本粘贴在下面:

'0':    249999,
'5':    249998,
'10':   249997,
'15':   249996,
'20':   249995,
'25':   249994,

可以找到其他文档内容here

知道为什么控制台可能会冻结?

2 个答案:

答案 0 :(得分:0)

文档的最大大小为1MB。请参阅Firestore documentation on quota and limits

  

文档的最大大小:1 MiB(1,048,576字节)

答案 1 :(得分:0)

有一个很酷的库,您可以用来确定文档的大小以及有关它的更多信息。

签出:https://github.com/alexmamo/FirestoreDocument-Android/tree/master/firestore-document

此库将告诉您您的文档大小,您可以检查文档是否小于当前的1Mbit配额

编辑

在这里,您可以看到如何使用此库获取文档大小,这非常简单,首先建立对要获取其大小的文档的引用,然后在该{{1上使用#include <iostream> #include <vector> // Whatever integral data type using MyType = unsigned long long int; // CLass for calculartin divisors incrementally struct Divisors { // Here we store the originally given numerator MyType numerator{}; // Persistent copy of the test value MyType testValue{ 1 }; // And here we will stor all divisors std::vector<MyType> allDivisors{}; // Constructor. Set all values to start Divisors(MyType number) : numerator(number), testValue(1), allDivisors{} {} // And a similar function to reset the class, in case we want to use it for an additional computation void reset(MyType number) { numerator = number; testValue = 1; allDivisors.clear(); } // Function, that will get the next divisor MyType nextDivisor() { // Here we will stor the result of the function. If we cannot // find a result any longer, then0 ist returned MyType result{}; // We run the loop until we have have found some divisor bool found{ false }; // Or until we are at the end while (!found && testValue <= numerator) { // Check if this value is a divisor if ((numerator % testValue) == 0) { // Yes, it is a divisor. Set flag to terminate the loop found = true; // Set the return value, so, the devisor result = testValue; // And store the divisor in our vector for later use allDivisors.push_back(testValue); } // Continue with next test value ++testValue; } // A valid divisor or 0, if no new divisors can be found return result; } }; // Some test code int main() { // We want to incrementally create divisors Divisors divisors(100ULL); // Call the next function for the divisor, until everything is found for (MyType d = divisors.nextDivisor(); d; d = divisors.nextDivisor()) std::cout << d << '\n'; // Show one divisor in each loop run return 0; } }}或.getSize()

DocumentReference

或者,该库具有一个方法,如果文档本身小于1Mbit,则该方法返回布尔值

QueryDocumentSnapshot

所以我们可以从上面的代码中完成

 myTaskIdRef.get().addOnCompleteListener(task -> {
            if (task.isSuccessful()) {
                DocumentSnapshot document = task.getResult();
                if (document.exists()) {
                    int documentSize = firestoreDocument.getSize(document);
                    String textToDisplay = "Size: " + documentSize + " bytes";
                    docSizeTextView.setText(textToDisplay);
                }
            }
        });

每次执行.getSize()时,它都会检查文档是否未达到配额,因此库会警告您当前的尺寸是否太大。

相关问题