{ Community }
  • Academy
  • Docs
  • Developers
  • Resources
    • Community Articles
    • Apigee on GitHub
    • Code Samples
    • Videos & eBooks
    • Accelerator Methodology
  • Support
  • Ask a Question
  • Spaces
    • Product Announcements
    • General
    • Edge/API Management
    • Developer Portal (Drupal-based)
    • Developer Portal (Integrated)
    • API Design
    • APIM on Istio
    • Extensions
    • Business of APIs
    • Academy/Certification
    • Analytics
    • Events
    • Hybrid
    • Integration (AWS, PCF, Etc.)
    • Microgateway
    • Monetization
    • Private Cloud Deployment
    • Insights
    • IoT Apigee Link
    • BaaS/Usergrid
    • BaaS Transition/Migration
    • Apigee-127
    • New Customers
    • Topics
    • Questions
    • Articles
    • Ideas
    • Leaderboard
    • Badges
  • Log in
  • Sign up

Get answers, ideas, and support from the Apigee Community

  • Home /
  • BaaS/Usergrid /
avatar image
4
Question by Robert Baker · Oct 10, 2014 at 11:10 AM · 1.2k Views baas

How to get paginated results from BAAS when SELECTing specific fields?

"Regular" requests (i.e. without as SQL-like parameter) to GET data from BAAS return a "cursor" property on the response object for supplying in subsequent requests to get the next set of entities.

If I issue a request to BAAS that includes an SQL string within the "ql" parameter, crucially, that selects specific fields as opposed to all fields, there is no cursor in the response.

Based on the the docs here:

http://apigee.com/docs/app-services/content/workin...

It suggests using a LIMIT clause within the SQL, which would be fine if there was also a way of doing OFFSET, but that does not seem to be the case (at least I cannot find this within the documentation). In the type of query where selecting specific fields, how do I get the data from the next set of results?

This combined with the fact that the maximum number that can be given to a LIMIT clause is 1000 leave me wondering how to do this?

Thanks,

-Rob

Comment
Add comment Show 2
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Michael Malloy ♦   · Oct 11, 2014 at 05:31 PM 0
Link

This has been forwarded to the engineering team for review and an answer will be posted once it is available.

avatar image Robert Baker · Oct 15, 2014 at 10:08 AM 0
Link

Hi Michael, is there any news on this please?

Close

3 Answers

  • Sort: 
avatar image
1

Answer by Dino   · May 21, 2015 at 05:39 PM

@asagar @Robert Baker

There is a way, it involves defining a function that is smarter about paginating through UG collections. Here's what I use:

/*
* ugCollectionForEach
*
* iterates through all items in a collection within Apigee Edge BaaS.
* Uses the Usergrid client object from the usergrid module.
*
* @param ugClient - the authenticated client object
* @param options - the options for a collection. Pass type and qs.
* @param f - function called with each UG entity. Accepts a single argument.
* @param doneCb - called in case of error or success.
*
*********************************************/
function ugCollectionForEach (ugClient, options, f, doneCb) {
  var results = {count: 0, failCount: 0};
  if ( ! options.qs) {
    doneCb(new Error('missing qs property in the options argument'), null);
  }
  if ( ! options.type) {
    doneCb(new Error('missing type property in the options argument'), null);
  }


  ugClient.createCollection(options, function (e, collection) {
    var e2;
    function doOnePage(collection, cb) {
      while(collection.hasNextEntity()) {
        f(collection.getNextEntity(), results);
        results.count++;
      }
      if (collection.hasNextPage()) {
        collection.getNextPage(function(e){
          if (e) {
            e2 = new Error('could not get next page of entities');
            e2.wrappedError = e;
            cb(e2, results);
          }
          else {
            doOnePage(collection, cb);
          }
        });
      }
      else {
        cb(null, results);
      }
    }


    if (e) {
      e2 = new Error('could not make or get collection');
      e2.wrappedError = e;
      doneCb(e2, null);
    }
    else {
      doOnePage(collection, doneCb);
    }
  });
}


//////////////////////////////////////////////////////////////////
//
// EXAMPLE Usage follows
//


ugCollectionForEach(ugClient,
                    {
                      type:'warehouses',
                      qs:{ql:'order by warehouseId', limit:50}
                    },
                    handleOneEntity,
                    function(e, info) {
                      if (e) {
                        console.log("error:" + JSON.stringify(e, null, 2));
                      }
                      else {
                        console.log("all done." + JSON.stringify(info, null, 2));
                      }
                    });




function handleOneEntity(entity, status) {
 ...
}

Comment
Add comment · Link
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by amuramoto · Oct 15, 2014 at 10:06 PM

You should be able to send the cursor from the previous response along with the query. For example, take this query

http://api.usergrid.com/myorg/sandbox/stores?&...

which returns this cursor in the body of the response

LTcxMDA0NTQzMjpnR2tBQVFFQWdITUFCblJoY21kbGRBQ0FkUUFRQjhjSHVsUzNFZVNTSElkU21xYU5zQUNBZFFBUUI4Y0hzRlMzRWVTQnlTYzFqWV9WTHdB

Now send the query and cursor to get the next page of results

http://api.usergrid.com/myorg/sandbox/stores?curso...

Then simply repeat with the next cursor that comes back. Hope this helps!

Comment
Add comment Show 3 · Link
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Robert Baker · Oct 16, 2014 at 08:14 AM 1
Link

The above does indeed work, but that is not the scenario I am describing in the question above. If I change your call to this:

http://api.usergrid.com/amuramoto/sandbox/stores?&...

Then there is no cursor. Indeed, there is no "entities" (list instead) property in the returned JSON response.

How do I get paginated results (including a cursor, or any other mechnaism to paginate) in this scenrio?

Thanks for your time.

avatar image seedmobi Robert Baker · Nov 27, 2014 at 04:06 PM 0
Link

I have the same problem

avatar image Dino ♦♦ seedmobi   · May 29, 2015 at 11:25 PM 0
Link

See my answer here: http://community.apigee.com/answers/4297/view.html

avatar image
0

Answer by Anil Sagar @ Google   · May 21, 2015 at 12:09 PM

Dear @Robert Baker ,

Unfortunately, This feature is not supported right now in usergrid API. There is a request regarding same in UserGrid backlog of issues here.

It does return CURSOR only if selected all fields in query language.

Cheers,

Anil Sagar

Comment
Add comment Show 1 · Link
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dino ♦♦   · May 29, 2015 at 11:24 PM 0
Link

See this answer for a workaround: http://community.apigee.com/answers/4297/view.html

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to get Group Users using android sdk. 2 Answers

Bass subscriber internal to external 1 Answer

GET on resource not returning anything but Duplicate error on POST 2 Answers

Sync stage data store with production 3 Answers

where can I find "create" and "run query" buttons in the Baas console? 1 Answer

  • Products
    • Edge - APIs
    • Insights - Big Data
    • Plans
  • Developers
    • Overview
    • Documentation
  • Resources
    • Overview
    • Blog
    • Apigee Institute
    • Academy
    • Documentation
  • Company
    • Overview
    • Press
    • Customers
    • Partners
    • Team
    • Events
    • Careers
    • Contact Us
  • Support
    • Support Overview
    • Documentation
    • Status
    • Edge Support Portal
    • Privacy Policy
    • Terms & Conditions
© 2019 Apigee Corp. All rights reserved. - Apigee Community Terms of Use - Powered by AnswerHub
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Create an article
  • Post an idea
  • Spaces
  • Product Announcements
  • General
  • Edge/API Management
  • Developer Portal (Drupal-based)
  • Developer Portal (Integrated)
  • API Design
  • APIM on Istio
  • Extensions
  • Business of APIs
  • Academy/Certification
  • Analytics
  • Events
  • Hybrid
  • Integration (AWS, PCF, Etc.)
  • Microgateway
  • Monetization
  • Private Cloud Deployment
  • Insights
  • IoT Apigee Link
  • BaaS/Usergrid
  • BaaS Transition/Migration
  • Apigee-127
  • New Customers
  • Explore
  • Topics
  • Questions
  • Articles
  • Ideas
  • Members
  • Badges