0

I have two documents one titled Album and the other titled Label. I am not sure I referenced the label id in the album document correctly but from searching around I think that is how it is done. If not I would appreciate the correction. What I want to do is pull up the album and the label in one query. something like db.find({"title": "myAlbum"} and then pull up the label document by saying "label_id": "someLabel" but I don't know how to syntactically do that. Any help would be appreciated.

the album document

 "_id" : ObjectId("550509f247c02cab8ecde099"),
 "title" : "myAlbum",
 "artist" : "singer",
 "published_date" : ISODate("2015-01-15T00:00:00Z"),
 "tracks" : 15,
 "label_id" : "someLabel"

the label document

"_id" : "someLabel",
"name" : "Label records",
"founded" : 1982,
"location" : "USA"
mryoyo
  • 3
  • 3
  • 1
    If you are looking for an automated way similar to SQL joins you won't find one. With schema like yours you have fetch album document, access label id and perform second query. If you use driver which supports [DBRefs](http://docs.mongodb.org/manual/reference/database-references/#dbref-explanation) you can simplify this process using helpers. – zero323 Mar 22 '15 at 19:57
  • pick your favorite from http://stackoverflow.com/questions/2350495/how-do-i-perform-the-sql-join-equivalent-in-mongodb ?? – mico Mar 22 '15 at 20:00
  • MongoDB does not support joins.You can refer an existing answer for similar question: [MongoDB query multiple collections at once](https://stackoverflow.com/questions/6502541/mongodb-query-multiple-collections-at-once) – Sai Mar 22 '15 at 19:57

0 Answers0