Google-cloud-node: Precondition failed when querying with multiple filters

Created on 1 Jul 2016  路  11Comments  路  Source: googleapis/google-cloud-node

When querying for a document, I need to check for equality for one field and an inequality for another field:

datastore.createQuery('MyDocument')
    .filter('playerId', '=', '11111111111111111111111111111111')
    .filter('created', '>', date)
    .limit(1)
    .run(function(err, data) {
        console.log(err);
        console.log(data);
    });

According to the docs, 'Inequality filters are limited to at most one property', and I have constructed my query within the parameters of this restriction. I get a 412 Precondition Failed error, with absolutely no useful information at all:

{ [Error: Precondition Failed] code: 412, metadata: Metadata { _internal_repr: {} } }

First: How do you get more information than an error code? I've been able to fix most of my issues just by guessing what the issue is, but it's not a sustainable practice.

Second: Is there anything wrong with my query that would cause it to fail like this?

I appreciate the help.

question datastore

All 11 comments

@pcostell can help with the second question. On the first, we are waiting for some changes upstream to pass down better errors to us; track here: #1378

@RobertHerhold have you made any progress with this?

// ping @pcostell

@stephenplusplus I have not. I was hoping a resolution on #1378 would be made soon so I could figure out what was wrong.

Sorry for the wait. I hope that can be resolved soon as well. @pcostell might have an update on where that stands as well.

@stephenplusplus Thanks for fixing #1378. I'll be revisiting this issue soon.

@stephenplusplus I've just tried it out with the changes in #1433, but I get exactly the same error message (or lack thereof)

That's a bummer. Thanks for trying it out, though. I added a comment to the issue tracking the Datastore error message dilemma: https://github.com/GoogleCloudPlatform/gcloud-node/issues/1378#issuecomment-232999199

Sorry I missed this:

You are getting a precondition failed because an index is required for the query you are trying to run. You need to upload an index.yaml file which looks like:

indexes:
- kind: MyDocument
   properties:
   - name: playerId
   - name: created

You can find more info about indexes here.

@pcostell Is there anyway I can do the same thing without the index.yaml file? Right now I'm using the datastore independently of GAE, although I will be migrating after I finish switching from my DB -> gcloud datastore

The index.yaml is a Cloud Datastore requirement, not an App Engine one.

You can upload your index.yaml file using gcloud:

gcloud preview datastore create-indexes index.yaml

Thanks @stephenplusplus and @pcostell. It works well now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mik115 picture mik115  路  5Comments

jackzampolin picture jackzampolin  路  3Comments

pputhran picture pputhran  路  4Comments

sporkd picture sporkd  路  5Comments

positlabs picture positlabs  路  3Comments