A
A
Arman2015-04-25 11:46:37
MongoDB
Arman, 2015-04-25 11:46:37

How to evenly split mongoId for folder structure?

Good afternoon.
As you know, it's better not to store a bunch of files in one folder and when you were on MySQL used the primary key. It turned out something like:
./001/323/leps.mp3
Now I'm trying to get the same thing from mongoId:
4af9f23d8ead0e1d32000000 I
thought to break it:
./4af9/f23d/8ead/0e1d32000000/leps.mp3
but there are doubts that the files will not lie evenly to disks. Through mongoId, you can find out the time of creation, maybe this will help somehow?
4af9f23d8ead0e1d32000000 -> 1257894461 // getTimestamp()
The folder will be
./125/789/4461/4af9f23d8ead0e1d32000000/leps.mp3
./894/461/4af9f23d8ead0e1d32000000/leps.mp3
It is advisable to store the id on the way, so as not to completely lose the connection. I also thought about storing the path to the file in the database, but somehow it confuses me, I want to be simpler
thanks;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lega, 2015-04-25
@lega

You can store files in the database (gridfs) using its advantages (indexes, sharding, extra information, full dump / restore, replica, etc.)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question