Using result returned by a query to form another query
===

I started exploring node.js & mongo recently and I am using mongojs library for accessing mongo from node.js.

I read a few resources on the net such as [this][1], [this][2] and [this][3]. But didn't really understand much. 

I am having a collection called 'customers' which has many customerIDs in it. There is a separate collection for each customerID. That is, if the customerIDs are A001, A002,etc there are collections with those names. So basically the 'customers' collection stores names of other collections. 
Here is a rough picture of the database:

    customers = {{ _id: 'A001' }
                 { _id: 'A002' }
                 { _id: 'A003' }
                }      
    A001 = {"name":"foo","zip":10000}     
    A002 = {"name":"bar","zip":10001}
    ....

I want to traverse the 'customers' collection, get the customer IDs from there & open the collection with that name & print it's contents.
    
    db.customers.find({},{_id:1},function(err, customers) { //finding the ids
      if( err || !customers) console.log("Error");
      else customers.forEach( function(customer) { //for each entry in the customers collection
    	getUsers(customer); //passing an customer id to a method
    
      } );
    });

    var getUserIDs = function(ids) { // A theoretical representation of what I want to do
    	db.ids.find({},function(err, ids) { // get all data from the collection specified  by 'ids'
          if( err || !ids) console.log("Error");
          else ids.forEach(function(id) {
             console.log(id["name"]);   	
    }
The getUserIDs method is just my though process, I haven't implemented it.

The type of the variable 'ids' which is passed on to getUserIDs method seems to be of type Object. How do I use this to make a query and accomplish what I wanted to? 

Thanks!


  [1]: http://www.mongodb.org/display/DOCS/SQL+to+Mongo+Mapping+Chart
  [2]: http://www.mongodb.org/display/DOCS/Queries+and+Cursors
  [3]: https://github.com/gett/mongojs