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
-
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; } }
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 ?