M
M
magary42015-07-07 10:44:49
JavaScript
magary4, 2015-07-07 10:44:49

When is it better to store images in the file system and when in the database?

actually switched from PHP to Node.js (Meteor) I see that there are many tools in mongo for storing files in the database

Answer the question

In order to leave comments, you need to log in

7 answer(s)
A
Andrey Burov, 2015-07-07
@BuriK666

You do not need to store files in the database, if the file is on disk, you can use sendfile (for example, in nginx).

I
Ivan, 2015-07-07
@LiguidCool

Compared to PHP, it's actually the same - everything is stored on disk, only the path is in the database.

S
ShamblerR, 2015-07-07
@ShamblerR

unambiguously on the file system, fish separately flies separately.
if you have a big problem with the size and number of files, then here you can recommend
1.ssd with missing heads as a class, as a result, the average file search time is 50K times higher.
2. With a very large number of files, the restrictions imposed by the file system will already be significant (to search for the latest), then you can follow the path of Zuckerberg, format the FILE! under ext2 = block device file. size 1x1 to the size of the screw itself, mount it as a device, in this case the file will be physically 1 and the search algorithm inside 1 file works faster than searching through the files themselves, so the profit will be obvious.
But it seems to me that this is not the case.
The database is not the fastest thing in the world at all, its main task is to make transactions, and you have to sacrifice something. In this case, speed. So storing something in the database is not a smart idea at all, and even more so things that without it generally live fine for themselves.

�
âš¡ Kotobotov âš¡, 2015-07-07
@angrySCV

in order to increase the speed of response, the results of requests are stored all together in one document, for example, in a person’s profile they often store lists of groups to which he is subscribed, also, for example, a photo of his avatar, which allows you to create a user profile at once with all the required data, from one request.
PS The
file system is the database!!!111111 so I think there is nothing much to discuss here, just compare the speed of different databases, and the convenience of working with them.
for example, for the file system, you already have various convenient tools for CRUD in the OS, and for monga, you need to kick programmers to work with photos)

N
nApoBo3, 2015-07-07
@nApoBo3

If you do not know exactly why to store in the database, store in files. If there are good reasons, store in the DB. It all depends on the architecture of the platform. IMHO files are more convenient, but one must understand that they entail additional backup and distributed storage technologies.

L
lega, 2015-07-08
@lega

in the database:
+ you can add specific indexes and use different queries to quickly get files
+ metadata can be stored along with the file
+ backup / dump is done immediately according to data and files
+ monge has sharding and a replica out of the box when files do not fit on the host or there is not enough io
- you need to make tools for distributing files
in the FS:
+ there are ready-made tools for distributing
- all other items from above (replica, metadata, dump separately, no indexes and queries)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question