Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6968917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:30:51+00:00 2026-05-27T16:30:51+00:00

i think i have a problem with my schema design for my music app.

  • 0

i think i have a problem with my schema design for my music app.

i have 3 collections: Artists, Tracks and Albums.
and 3 classes: artists, albums and tracks

document from artists:

         [_id] => MongoId Object
            (
                [$id] => 4ee5bbfd615c219a07000000
            )
        [freeze] => false,
        [genres] => Array,
        [hits] => 0,
        [name] => Sarya Al Sawas,
        [pictures] => Array,

document from albums:

        [_id] => MongoId Object
            (
                [$id] => 4ee88308615c218128000000
            )

        [name] => Sabia
        [slug] => wafiq-habib-ft-sarya-al-sawas-sabia
        [year] => 1999
        [genres] => Array,
        [pictures] => Array,
        [artists] => Array
            (
                [0] => MongoId Object
                    (
                        [$id] => 4ee34a3b615c21b624010000
                    )

                [1] => MongoId Object
                    (
                        [$id] => 4ee5bbfd615c219a07000000
                    )

            )

document from tracks

            [_id] => MongoId Object
            (
                [$id] => 4ee8a056615c21542a000000
            )

        [name] => Bid Ashok
        [slug] => wafiq-habib-ft-sarya-al-sawas-bid-ashok
        [genres] => Array,
        [file] => /m/tracks/t.4ee8a05540c624.04707814.mp3,
        [freeze] => false,
        [hits] => 0,
        [duration] => 303,
        [albums] => Array
            (
                [0] => MongoId Object
                    (
                        [$id] => 4ee5cbc3615c216509000000
                    )

            )

        [artists] => Array
            (
                [0] => MongoId Object
                    (
                        [$id] => 4ee5bbfd615c219a07000000
                    )

                [1] => MongoId Object
                    (
                        [$id] => 4ee34a3b615c21b624010000
                    )

            )

first of all is that good schema design ??!
i designed this schema this way because of many to many relationships
sometimes tracks have 2 artists, and albums have 2 artists.

anyway i have problem querying the albums that attached to specific track.

lets say i’m on the artist page

  1. i need to get all the artist albums and tracks so i do this:

    $cursors = array(
        'albums' => $this->albums->find(array('artists' => $artist->_id))->sort(array('_id' => -1)),
        'tracks' => $this->tracks->find(array('artists' => $artist->_id))->sort(array('_id' => -1)),
        'clips'  => $this->clips->find(array('artists' => $artist->_id))->sort(array('_id' => -1))
    );
    foreach($cursors as $key => $cursor) {
        foreach($cursor as $obj) {
            $obj['name'] = ($this->lang->get() != 'ar' ? $obj['translated']['name'] : $obj['name']);
            $obj['by']   = $this->artists()->get($obj['artists'])->toString('ft');
            ${$key}[]    = $obj;
        }
    }
    
  2. i need to loop on all tracks and get their album names lets say this artist has 3000 tracks
    i think it will be very slow….

so my question is: Is That a good Schema Design ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:30:51+00:00Added an answer on May 27, 2026 at 4:30 pm

    Well, this is a very relational problem, and using a non-relational database for such a problem requires some effort. In general, I think your schema design is good.

    What you’re describing is called “the N+1 problem”, because you’ll have to make N+1 queries for N objects (in your case, it’s more complicated, but I guess you get the idea).

    Some remedies:

    • You can use the $in operator to find e.g. all tracks of a certain artist:

      db.tracks.find({"artists" : { $in : [artist_id_1, artist_id_2, ...] } });
      

      This doesn’t work if the array of artists grows huge, but a few hundred, maybe a thousand should work fine. Make sure artists is indexed.

    • You can denormalize some of the information that is needed very often. For example, you might want to show the track list very often, so it makes sense to copy the artist’s names to every track. Denormalization depends mostly on what you’re trying to achieve from an end-user perspective. You might not want to store each and every artist’s name in full, but only the first 50 characters because the UI doesn’t show more in the overview anyway.

      In fact, you’re already denormalizing some data, such as the artist ids in album (which are redundant, because you could get them via the tracks as well). This makes queries easier, but it will be more write-heavy. Updates are ugly because you’ll have to make sure they propagate through the system.

    • In some cases, it might make sense to ‘join’ on the client(!) rather than the server. This doesn’t really fit your problem well, but it’s noteworthy: suppose you have a list of friends. Now the sever will have to look up each friend’s name whenever it displays them. Instead, it could provide you with a lookup table ids/friends, and the server only serves the ids. Some JavaScript could replace the ids with the real names from the client’s cache.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have a problem in sending data from php to pdf. I think
I have an HBase schema-design related question. The problem is fairly simple - I
I think I have a problem in understanding the proper way of using MVC.
I think I have a synchronization problem...It may be too basic..Please help.. I have
I think i have a basic problem in understanding the dojo toolkit. Well I
I have a problem with a template and pointers ( I think ). Below
I have a problem drawing something quickly in .NET. I don't think that any
i have a problem that i can't solve ! (sqlite3, but i think it
I have a peculiar problem, which I think that a lot of other people
I have been having the following problem, i think it's probably due to the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.