I have 3 collections in MongoDB that cannot have their schema changed. Some queries need to access the 3 collections.
I know that I need multiple queries to do this but I'm not sure what the most efficient method of doing this is. The folllowing example is simplified :
My data contains a "User" collection that serves as a logical parent to the other two collections. The other two collections are "DVD" and "CD". A user can have multiple CDs or DVDs
User Document
id : "jim",
location : "sweden"
CD Document
name : "White Album",
owner : "jim"
DVD Document
name : "Fargo",
owner : "jim"
Now, the approach I am currently taking is as follows. If I want get back all of the CDs and DVDs for users in Sweden.
Step 1
Get all users in Sweden and return a cursor
Step 2
Iterate through the each user in the cursor and perform a lookup on both the DVD and CD collections to see if the users id matches the owner field
Step 3
If it does add the user to an array to be returned
This approach requires 2 additional queries and seems really inefficient to me. Is there a more efficient way of doing this?