title: Proper way to query and match multiple data points Apigee
body: <p>I am building an app that does the following: </p>
  
  <ol>
  <li>Grab Friends from Facebook </li>
  <li>Select 1-2 friends and add them to a
  group</li>
  </ol>
  
  <p>I want users to be able to login with Facebook and have it look through all the groups and bring back any that their friends may be in. Each group is saved in Apigee with a 1-2 Facebook id properties.</p>
  
  <p>I am not sure the best way to accomplish this. </p>
  
  <p>Below is just what I did to at least give it a try. Obviously sending a request every time I loop through the friends is a horrible idea. </p>
  
  <p>Help please?</p>
  
  <p><a href="http://apigee.com/docs/app-services/content/querying-your-app-services-data" rel="nofollow noreferrer">http://apigee.com/docs/app-services/content/querying-your-app-services-data</a></p>
  
  <pre><code>function get_groups(){
  
     //Stores array of friend ids
     var friends = [];
  
     //Request to Facebook and get friends
     FB.api('/me/friends', 'GET', function(data){
  
         for (i = 0; i &lt; data.data.length; i++){
             friends.push(data.data[i].id);
         }
         request(friends)
     });
  
     function request(friends){
  
      for ( i = 0; i &lt; friends.length ; i++) {
  
          //Set ids to look for in the groups
          var options = {
              endpoint:"groups",
              qs:{ql: "id1='" + friends[i] + "' or id2='" + friends[i] +"'"},
          }
          //Request to Apigee to query groups 
          client.request(options, function (err, data) {
              if (err) {
                   console.log(err);
              } else {
                  //do something with the data
              }   
          });     
        }
     }
  }
  </code></pre>