VipulVyas
VipulVyas

Reputation: 71

Paginate API call on multiple dependent database query

I am tying to do pagination call on database query, in normal single query it is working fine but scenario is like, there is 3 DB query in single API and also there is filtering after first or second DB call so how to achieve pagination in that ? I am using skip and limit for pagination DB query. ex.:

Pagination {
   output1 = Query1
   dataForQ2 = []  
    for (output of output1){
        if (output.isValid === true){
         continue;
          }
          dataForQ2.push(output);
     }
    output2 = Query2(dataForQ2) // Query2 is depends on filtered data
    dataForQ3 = [];
     for (output of output2){
        if (output.isValid === true){
         continue;
          }
          dataForQ3.push(output);
     }
    result = Query3(dataForQ3)  // Query3 is depends on filtered data of Query2
   
}

if i set Limit = 10 and skip = 0 on first query then Query1 give 10 record second query it can be 10,8 or 7 because of filtered data of Query1, in Query3 can be 10,5,4. but i want 10 record. how to solve this.

Tech : node, mysql, mongo

Upvotes: 0

Views: 704

Answers (0)

Related Questions