Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I've yet to look into storing files such as Word, Excel, etc. into MongoDB seriously and I want to know - am I able to store whole docx or excel files in MongoDB and then RETRIEVE them via querying?

like image 618
PinkElephantsOnParade Avatar asked Jun 20 '12 15:06

PinkElephantsOnParade


2 Answers

Using gridfs yes.

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

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

It's normal implementation is to break down your big documents into smaller ones and store those aprts in a chunks collection mastered by a fs.files collection which you query for your files.

like image 109
Sammaye Avatar answered Sep 22 '22 16:09

Sammaye


MongoDB is a document database that stores JSON-like documents (called BSON). Maximum size of a BSON object is 16 megabytes, which may be too little 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 retriving complete documents (whatever their sizes are).

As far as I know, Mongoose doesn't support GridFS. However, you can use GridFS via its native driver's GridStore. Just run npm install mongodb and start hacking!

like image 37
jsalonen Avatar answered Sep 21 '22 16:09

jsalonen