Skip to content

How are query start cursorTokens used? #1208

Description

@mcfarljw

My application is using express and I'm having some troubles getting the latest ~0.30.0 releases to return a cursor value I can pass back to the client for usage. If I recall correctly the previous releases were using a base64 string. What kind of cursorToken should I be passing a start query now?

https://googlecloudplatform.github.io/gcloud-node/#/docs/v0.30.2/datastore/query?method=start

datastore.runQuery(
    datastore.createQuery('User').start(???).limit(1),
    function(error, entities, cursor) {
        // cursor used to return base64 startVal
    }
);

Maybe I should manually convert it myself now?

new Buffer(cursor.startVal).toString('base64')

Activity

  1. mcfarljw commented on Apr 6, 2016

    @mcfarljw
    ContributorAuthor

    I've just spent a bit of time looking into the issue and did get it working. Here is what I came up with:

    var cursorToken = req.cursorToken ? new Buffer(req.cursorToken, 'base64') : null;
    datastore.runQuery(
        datastore.createQuery('User').start(cursorToken).limit(1),
        function(error, entities, nextQuery) {
            var result = {};
            result.cursorToken = new Buffer(nextQuery.startVal).toString('base64');
            res.status(200).json(result);
    );
    

    It might make things a bit more straightforward and easier to work with if the start method would accept both base64 and buffer parameters. It might also be convenient for the nextQuery to include a base64 version called endCursorToken and startCursorToken so that it matches up a bit more with the documentation.

  2. stephenplusplus commented on Apr 6, 2016

    @stephenplusplus
    Contributor

    I think we should just go back to only accepting base64 strings and skip buffers altogether. Any interest in putting a PR together?

  3. mcfarljw commented on Apr 6, 2016

    @mcfarljw
    ContributorAuthor

    I'll take a shot at making a PR for this and see what happens.

  4. stephenplusplus commented on Apr 6, 2016

    @stephenplusplus
    Contributor

    Thanks! Feel free to send it in even if it's not perfect. I can always help with the grunt work (code style, tests, etc).

  5. stephenplusplus commented on Apr 7, 2016

    @stephenplusplus
    Contributor

    Fixed via a80ff9b

  6. added a commit that references this issue on Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

api: datastoreIssues related to the Datastore API.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions