2017-10-14 111 views
0

我小說的集合,如下所示:MongoDB的文件大小限制

enter image description here

的詞數組包含的所有單詞,涉及到每個單詞的其他語言信息。當我嘗試添加較長的文本(10萬個字+),我得到的錯誤:

的RangeError:嘗試寫入外緩衝區範圍

其中,我已經收集,意味着該BSON文件大於16 MB因此超過了限制。

我假設這是一個比較常見的情況。我現在正在考慮如何解決這個限制 - 例如,我可以將這部小說分成10k字的各種大小。或者這是否意味着文檔應該組成一個單獨的集合(即每個文本上傳一個新集合) - 這對我來說是最不合適的。

在這種情況下,是否有標準/建議的方法來設計MongoDB數據庫?

另外,是否有可能在JS/Node中插入文檔之前檢查BSON的大小?

回答

0

您是否絕對需要將書籍的內容存儲在MongoDB中?如果您只是向用戶提供內容或批量處理內容,我建議將它們存儲在磁盤或AWS S3存儲桶或類似存儲中。

如果你需要的書內容住在數據庫,請嘗試使用MongoDB的GridFS的:

GridFS is a specification for storing and retrieving files that exceed the BSON-document size limit of 16 MB.

Instead of storing a file in a single document, GridFS divides the file into parts, or chunks, and stores each chunk as a separate document

When you query GridFS for a file, the driver will reassemble the chunks as needed. You can perform range queries on files stored through GridFS. You can also access information from arbitrary sections of files, such as to 「skip」 to the middle of a video or audio file.

在這裏閱讀更多: https://docs.mongodb.com/manual/core/gridfs/