Google-cloud-node: Datastore emulator always returns `MORE_RESULTS_AFTER_LIMIT`

Created on 11 Jul 2018  路  4Comments  路  Source: googleapis/google-cloud-node

Environment details

  • OS: Alpine (Dockerfile with FROM google/cloud-sdk:alpine)
  • Node.js version: 8.11.1
  • npm version: 5.6.0
  • google-cloud-node version: "@google-cloud/datastore": "1.4.1"

Steps to reproduce

I am following the example in the documentation (https://cloud.google.com/datastore/docs/concepts/queries#cursors_limits_and_offsets) to create an express endpoint to fetch a list of _Products_ from the datastore emulator, which looks like follows:

const datastore = new Datastore({
  namespace: 'products',
  projectId: 'xxx',
});

const addIds = payload => payload.map(item => ({ id: item[datastore.KEY].id, ...item }));

module.exports = ({ query: { endCursor, pageSize } }, response, next) => {
  let query = datastore.createQuery('Products').limit(pageSize);
  if (endCursor) {
    query = query.start(endCursor);
  }
  datastore.runQuery(query)
    .then(([products, information]) => {
      response.send({
        information,
        payload: addIds(products),
      });
      next();
    })
    .catch(() => {
      response.sendStatus(500);
      next();
    });
};

In every response from the emulator the information object holds a shape as below:

{
  "moreResults":"MORE_RESULTS_AFTER_LIMIT",
  "endCursor":"xxx"
}

The value of the endCursor changes on each request (when I pass the previous one in), except for when the end is reached where it then stays the same every time (Using a pageSize of _2_).

The value of the moreResults key is always MORE_RESULTS_AFTER_LIMIT even when the end is reached (I only have 7 entities under the Products key).

From the documentation it seems like the moreResults key should be NO_MORE_RESULTS when there are no more results to show.

I have currently added a workaround where I don't return information when the list of entities is empty, but that would always cause one more request than what is actually required.

I see there is a similar issue open on the google-cloud-datastore repo here: https://github.com/GoogleCloudPlatform/google-cloud-datastore/issues/130

And a similar closed issue (a rather old one) in the google-cloud-node repo which deals with a similar issue: https://github.com/GoogleCloudPlatform/google-cloud-node/issues/1260

I feel I am either missing something obvious or there is still a bit of a bug with the emulator.

the result is the same regardless of whether I treat the runQuery result as a _promise_ or pass it a _callback_.

Most helpful comment

Is it gonna be fixed? Still present.

All 4 comments

If this is the incorrect place for the issue I will gladly close and recreate it where appropriate.

Unfortunately, it seems that the emulator still has the bug. I'll ping in the issue over on google-cloud-datastore.

Is it gonna be fixed? Still present.

Still present.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ddunkin picture ddunkin  路  3Comments

jmdobry picture jmdobry  路  3Comments

pputhran picture pputhran  路  4Comments

sabrehagen picture sabrehagen  路  4Comments

stephenplusplus picture stephenplusplus  路  4Comments