const datastore = require('@google-cloud/datastore')({
projectId: 'captureappprod',
keyFilename: '/path/to/key.json' // key optained from App engine / IAM admin / service accounts
});
function deviceCount(start, count=0) {
const batchSize = 300;
const query = datastore.createQuery('Device') // Device is the 'kind'
.limit(batchSize)
.filter('app', '=', 'groove'); // key = value you are searching for
if (start) {
query.start(start);
}
datastore.runQuery(query)
.then(queryResult => {
console.log(`Getting ${batchSize} devices cursor: ` + start);
const devices = queryResult[0];
count += devices.length;
const info = queryResult[1];
if (info.moreResults != datastore.NO_MORE_RESULTS) {
deviceCount(info.endCursor, count + devices.length); // recursivly get more from the last cursor pointer
}
console.log(info.endCursor, count);
});
}
deviceCount();
Last active
July 10, 2017 08:08
-
-
Save willm/3726d7d6d24fa6093b524c058abbf0fd to your computer and use it in GitHub Desktop.
App engine
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment