title: RXJS expand operator
body: <pre><code>var offset = 1;
  var limit = 500;
  
  var list = new Promise(function (resolve, reject) {
    rets.getAutoLogoutClient(config.clientSettings, (client) =&gt; {
      var results = client.search.query(SearchType, Class, Query, {
        limit: limit,
        offset: offset
      });
      resolve(results);
    });
  });
  
  var source = Rx.Observable.fromPromise(list);
  
  source.subscribe(results =&gt; console.log(results.count));
  </code></pre>
  
  <p>I am doing a real estate site, using RETS. </p>
  
  <p>What I am trying to do my query are limited from the RETS server, is run this in a loop increasing my Offset until I have all my data. I don't know what the count is until I run the query and find the count value. </p>
  
  <p>I have tried to use expand but I have no clue of how exactly it works. Tried to do these multiple ways, even using the old fashion while loop, which while doesn't work with .then method. So I have turned to RXJS since I been using it in Angular 4. </p>
  
  <p>This is done in express. I need to eventually run corn jobs to fetch for updated properties, but my problem is fetching all the data and increasing the offset each time if the count is higher than my offset. So for example, run a query with an offset of 1 with a limit of 500. Total here is 1690. So next go around my offset would be:</p>
  
  <pre><code>offset += limit
  </code></pre>
  
  <p>Once I have my data, I need to save it to MongoDB. Which I already been able successfully to do. It's just finding a way to get all the data without having to manually set my offset.</p>
  
  <p>Note the server limit is 2500, yes I can fetch all this in one shot but there are also other data, such as media, which could have well over 2500. </p>
  
  <p>Any suggestions?  </p>