Sequential Access and Cursors

    If the number of query results is expected to be big, it is possible to limit the amount of documents transferred between the server and the clientto a specific value. This value is called batchSize. The batchSize_can optionally be set before or when a simple query is executed.If the server has more documents than should be returned in a single batch,the server will set the _hasMore attribute in the result. It will alsoreturn the id of the server-side cursor in the id attribute in the result.This id can be used with the cursor API to fetch any outstanding results fromthe server and dispose the server-side cursor afterwards.

    The initial batchSize value can be set using the setBatchSize_method that is available for each type of simple query, or when the simplequery is executed using its _execute method. If no batchSize valueis specified, the server will pick a reasonable default value.

    checks if the cursor is exhaustedcursor.hasNext()

    The hasNext operator returns true, then the cursor still hasdocuments. In this case the next document can be accessed using thenext operator, which will advance the cursor.

    Examples

    Show execution results

    1. {
    2. "_key" : "73337",
    3. "_id" : "five/73337",
    4. "_rev" : "_ZP4PTjK---",
    5. "name" : "one"
    6. }
    7. {
    8. "_key" : "73339",
    9. "_id" : "five/73339",
    10. "_rev" : "_ZP4PTjO---",
    11. "name" : "two"
    12. }
    13. {
    14. "_key" : "73341",
    15. "_id" : "five/73341",
    16. "_rev" : "_ZP4PTjO--A",
    17. "name" : "three"
    18. }
    19. {
    20. "_key" : "73343",
    21. "_id" : "five/73343",
    22. "_rev" : "_ZP4PTjS---",
    23. "name" : "four"
    24. }
    25. {
    26. "_key" : "73345",
    27. "_rev" : "_ZP4PTjS--A",
    28. "name" : "five"
    29. }

    Hide execution results

    Next

    returns the next result documentcursor.next()

    If the hasNext operator returns true, then the underlyingcursor of the simple query still has documents. In this case thenext document can be accessed using the next operator, whichwill advance the underlying cursor. If you use next on anexhausted cursor, then undefined is returned.

    Examples

    1. {
    2. "_key" : "73355",
    3. "_id" : "five/73355",
    4. "_rev" : "_ZP4PTjq---",
    5. "name" : "one"
    6. }

    Hide execution results

    sets the batch size for any following requests

    Sets the batch size for queries. The batch size determines how many resultsare at most transferred from the server to the client in one chunk.

    Get Batch size

    returns the batch sizecursor.getBatchSize()

    Returns the batch size for queries. If the returned value is undefined, theserver will determine a sensible batch size for any following requests.

    executes a queryquery.execute(batchSize)

    Executes a simple query. If the optional batchSize value is specified,the server will return at most batchSize values in one roundtrip.The batchSize cannot be adjusted after the query is first executed.

    Note: There is no need to explicitly call the execute method if anothermeans of fetching the query results is chosen. The following two approacheslead to the same result:

    Show execution results

    1. [
    2. {
    3. "_key" : "74029",
    4. "_id" : "users/74029",
    5. "_rev" : "_ZP4PUES---",
    6. "name" : "Gerhard"
    7. },
    8. {
    9. "_key" : "74031",
    10. "_id" : "users/74031",
    11. "_rev" : "_ZP4PUES--A",
    12. "name" : "Helmut"
    13. },
    14. {
    15. "_key" : "74033",
    16. "_id" : "users/74033",
    17. "_rev" : "_ZP4PUEW---",
    18. "name" : "Angela"
    19. }
    20. ]

    Hide execution results

    Show execution results

    1. {
    2. "_key" : "74012",
    3. "_id" : "users/74012",
    4. "_rev" : "_ZP4PUDu--A",
    5. }
    6. {
    7. "_key" : "74014",
    8. "_id" : "users/74014",
    9. "_rev" : "_ZP4PUDy---",
    10. "name" : "Helmut"
    11. }
    12. {
    13. "_key" : "74016",
    14. "_id" : "users/74016",
    15. "_rev" : "_ZP4PUDy--A",
    16. "name" : "Angela"
    17. }
    18. SimpleQueryAll(users)
    19. {
    20. "_key" : "74012",
    21. "_id" : "users/74012",
    22. "_rev" : "_ZP4PUDu--A",
    23. "name" : "Gerhard"
    24. }
    25. {
    26. "_key" : "74014",
    27. "_id" : "users/74014",
    28. "_rev" : "_ZP4PUDy---",
    29. "name" : "Helmut"
    30. }
    31. {
    32. "_key" : "74016",
    33. "_id" : "users/74016",
    34. "_rev" : "_ZP4PUDy--A",
    35. "name" : "Angela"
    36. }
    37. SimpleQueryAll(users)

    Hide execution results

    Dispose

    disposes the result

    If you are no longer interested in any further results, you should calldispose in order to free any resources associated with the cursor.After calling dispose you can no longer access the cursor.

    counts the number of documentscursor.count()

    The count operator counts the number of document in the result set andreturns that number. The count operator ignores any limits and returnsthe total number of documents found.

    Note: Not all simple queries support counting. In this case null isreturned (Simple queries are deprecated).

    cursor.count(true)

    If the result set was limited by the limit operator or documents wereskiped using the skip operator, the count operator with argumenttrue will use the number of elements in the final result set - afterapplying limit and skip.

    Note: Not all simple queries support counting. In this case null isreturned (Simple queries are deprecated)..