FROM google/cloud-sdk:alpine)8.11.15.6.0"@google-cloud/datastore": "1.4.1"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_.
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.
Most helpful comment
Is it gonna be fixed? Still present.