GeezerVison is showing github.com — Datastore query fails when including a sort and a filter. · Issue #1402 · googleapis/google-cloud-node
Datastore query fails when including a sort and a filter. #1402Descriptiongcloud datastore.runQuery fails with a "412 Precondition Failed" when the query contains a filter and a sort. Below is a mocha test that creates a new datastoreKind, adds two records, then queries for the record. The only difference between the queries is that the third query contains both a filter and a sort.
'use strict';
var datastore = require('gcloud').datastore({
projectId: 'test-playground',
keyFilename: './serviceAccountCredentials.json'
});
var kind = 'Scratch-' + require('node-uuid').v4();
describe('Datastore Filter', function () {
it('should add two records', function (done) {
datastore.upsert({
key: {namespace: 'Scratch', path: [kind]},
data: {category: 'Scratch', date: new Date(), text: 'Find me too!'}
}, function () {
datastore.upsert({
key: {namespace: 'Scratch', path: [kind]},
data: {category: 'Scratch', date: new Date(), text: 'Find me!'}
}, done);
});
});
it('should find records sorted by date', function (done) {
var query = datastore
.createQuery('Scratch', kind)
.order('date', {descending: true});
datastore.runQuery(query, function (err) {
if (err) done(err);
else done();
});
});
it('should find records matching a filter', function (done) {
var query = datastore
.createQuery('Scratch', kind)
.filter('category', 'Scratch');
datastore.runQuery(query, function (err) {
if (err) done(err);
else done();
});
});
it('should find records matching a filter sorted by date', function (done) {
var query = datastore
.createQuery('Scratch', kind)
.filter('category', 'Scratch')
.order('date', {descending: true});
datastore.runQuery(query, function (err) {
if (err) done(err);
else done();
});
});
});
Activitychanged the title [-]Datastore query fails when including a filter.[/-] [+]Datastore query fails when including a sort and a filter.[/+] on Jun 30, 2016bamapookie commented on Jun 30, 2016 ContributorAuthor More actions Note: Updated to include that the combination of sort and filter causes the failure. stephenplusplus commented on Jun 30, 2016 pcostell commented on Jun 30, 2016 The combination of filter and sort requires an index to be defined. You should have an index.yaml file that includes:
indexes:
- kind: Scratch
properties:
- name: category
- name: date
direction: desc
bamapookie commented on Jul 1, 2016 ContributorAuthor More actions Thanks. I updated the original comment to be consistent with the updated code.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|