Home > Net >  should i keep songs and their info separate?
should i keep songs and their info separate?

Time:09-02

hello everyone to be honest I'm a junior Mern-stack developer and trying to build a music player as my project, but there is a technical question : where should i keep the songs and their info ?

what do you do in this case ? should i keep my songs on the server and their info on MongoDB ? if so, how can i find a songs info from database while they have no relation ?

to make it some more clear for you guys i should tell you that I'm using Node.js , express, multer ( for saving uploaded song ) modules for this project .

CodePudding user response:

Well you can save the file on your server and add a collection called Music por example, with the music file name and then the music title, artist, and so on and so forth, like:

{
  "name": "Immigrant Song",
  "artist": "Led Zeppelin",
  "album": "Led Zeppelin III",
  "release_date": "1970",
  "file_name": "immigrant_song.mp3"
}

CodePudding user response:

where should i keep the songs and their info

If you want to be able to do complex queries of the songs then, you probably keep their info (title, artist, genre, date, length, etc...) in a database where you can query that info using normal database features.

The songs themselves can be stored in your server's file system as individual files. When you save the info to the database, you can save either the filename or full path in the database so when you find a song you want in the database, you then know where to get it in the file system.

should i keep my songs on the server and their info on MongoDB ?

There's no absolute right answer to a question like this as there are many ways to do things, but keeping the songs in the server file system and the metadata about each song in the database is a perfectly fine way of doing things.

In a similar type of problem, I use a couple of image editing tools (Adobe Lightroom and Capture One) and they do something similar. They have a database that is used for all the metadata about images (shoot date, rating, size, lens used, aperture, shutter speed, etc...) and the actual photos themselves are stored in the file system. The database contains a filename so when they want to connect the actual image to the metadata in the database, they know where to get the image from in the file system. Same concept.

if so, how can i find a songs info from database while they have no relation ?

You must store in the database with the song info, some id or filename or path that allows you to construct a filename on your server to retrieve the actual song file.

  • Related