MongoDB: How to store files (Word, Excel, etc.)?

I still need to seriously study files, such as Word, Excel, etc., in MongoDB, and I want to know if I can store entire docx or excel files in MongoDB, and then RETRIEVE them through a query?

+6
source share
2 answers

Using gridfs yes.

Gridfs is a storage specification. It is not built into the database, but instead into drivers.

You can find out more here: http://www.mongodb.org/display/DOCS/GridFS .

This common implementation is to split your large documents into smaller ones and store these aprts in the chunks collection, which was created by the fs.files collection that you request for your files.

+14
source

MongoDB is a document database that stores JSON-like documents (called BSON ). The maximum size of a BSON object is 16 megabytes , which may be too small for some use cases.

If you want to store binary data of arbitrary size, you can use GridFS ( http://www.mongodb.org/display/DOCS/GridFS+Specification ). GridFS automatically splits your documents (or any binary data) into several BSON objects ( usually 256k in size ), so you only need to worry about storing and retrieving complete documents (regardless of their size).

As far as I know, Mongoose does not support GridFS. However, you can use GridFS through the native GridStore driver . Just run npm install mongodb and start hacking!

+6
source

Source: https://habr.com/ru/post/918573/


All Articles