Friday, 28 April 2017

mongoose perform several requests and promises

I'm working with mongoose in node. I'm doing requests to get paged-like content, in a particular case I need to parse data from several of those requests.

Now I'm doing...

function handler(data, size, start, n) {
  # process data 
  processed_data=[]
  # ...
  if(processed_data.length <= size)

    return processed_data;

  else 
    mongoose.model('model').find({}, function(err, data){ 

        handler(data, size, start, n);

    }).skip(start).limit(n);
}

mongoose.model('model').find({}, function(err, data){ 

    handler(data, size, n, mysize);

}).skip(n).limit(mysize);

The code is working fine and I can process the entire model collection.
Is there any approach or solution providing any performance advantage to this one?

Any help would be appreciated.



via Karlos

No comments:

Post a Comment