在Google数据存储区查询中多次选择引发ApiError:Precondition节点中的失败错误 [英] Multiple select in google datastore query throwing ApiError: Precondition Failed error in node
问题描述
我使用以下查询从Google Datastore中检索一些实体:
var query = datastore.createQuery(namespace,tableName); query.select(['displayName','username']); datastore.getEntitySet(query,function(err,data){if(err){res.status(500).end();} else {res.send (data);}});
如果我只选择一个属性,即
query.select('username');
但是多选择其投掷412'Precondition Failed'错误。我的实体如下所示:
实体属性
您需要创建多属性索引才能使用多属性查询。
因为您没有使用App Engine,所以需要手动创建这些索引。
- 安装Java 7 Runtime(或更高版本) http://java.com/
- 我建议使用 Cloud Shell ,其中已安装并已配置Java
- 创建一个名为WEB-INF的文件夹
- 在该文件夹中,您ed三个文件:
- appengine-web.xml (用您的项目ID替换YOUR_PROJECT_ID_HERE)
- web.xml
- datastore-indexes.xml (删除用于我的示例的索引)
- appengine-web.xml (用您的项目ID替换YOUR_PROJECT_ID_HERE)
- datastore-indexes.xml文件,您需要定义您的多属性索引。 查看文档。
- 安装 gcd工具
- 最后,运行gcd工具(位于WEB-INF文件夹之上的一个目录)
- Linux / Mac
path / to / gcd.sh updateindexes --auth_mode = oauth2。
- Windows
路径/ to / gcd.cmd updateindexes --auth_mode = oauth2。
几分钟后,应该创建索引。 / p>
I'm using following query to retrieve some entities from google Datastore:
var query = datastore.createQuery(namespace,tableName); query.select(['displayName','username']); datastore.getEntitySet(query,function(err,data){ if(err){ res.status(500).end(); } else{ res.send(data); } });
The above code works fine if I select only one property i.e.
query.select('username');
But with multiple select its throwing 412 'Precondition Failed' error. my entity looks like the following: Entity properties
解决方案You need to create a multi-property index in order to use multi-property queries.
Because you are not using App Engine, these indexes need to be manually created.
I have a tutorial here that covers this.
Here are the steps:
- Install Java 7 Runtime (or later version) http://java.com/
- I recommend using Cloud Shell which has Java already installed and configured
- Create a folder called WEB-INF
- Inside that folder, you need three files:
- appengine-web.xml (replace YOUR_PROJECT_ID_HERE with your project ID)
- web.xml
- datastore-indexes.xml (Remove the indexes I used for my sample)
- In the datastore-indexes.xml file, you need to define your multi-property indexes. Follow the documentation.
- Install the gcd tool
- Finally, run the gcd tool (one directory above the WEB-INF folder)
- Linux/Mac
path/to/gcd.sh updateindexes --auth_mode=oauth2 .
- Windows
path/to/gcd.cmd updateindexes --auth_mode=oauth2 .
- Linux/Mac
After a few minutes, your indexes should be created.
这篇关于在Google数据存储区查询中多次选择引发ApiError:Precondition节点中的失败错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- Install Java 7 Runtime (or later version) http://java.com/
- Linux / Mac