tkroman
tkroman

Reputation: 4798

Using MongoDB's for storing files of size est. 500KB

In GridFS FAQ there is said that one should store in aforementioned GridFS files of size >16MB. I have a lot of files ~500KB.

Question is: which approach is more efficient - storing files' content inside document or storing file itself in GridFS? Should I consider other approaches?

Upvotes: 0

Views: 189

Answers (1)

supershabam
supershabam

Reputation: 706

As for efficiency, either approach is the same. GridFS is implemented at the driver level by paging your >16MB data across multiple documents. MongoDB is unaware that you're storing a "file", it just knows how to store documents and doesn't ask questions.

So, depending on your driver (PHP/NodeJS/Ruby), you may find some metadata features nice and opt to use GridFS because of that. Otherwise, if you are absolutely sure a document will not be larger than 16MB, storing the raw content in the document should be fairly simple and just as fast (or faster).

Generally, I'd recommend against storing files in the database. It can have a negative impact on your working set and overall speed.

Upvotes: 5

Related Questions