Multiple select in google datastore query throwing ApiError: Precondition Failed error in node
Multiple select in google datastore query throwing ApiError: Precondition Failed error in node
我正在使用以下查询从 google 数据存储中检索一些实体:
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);
}
});
如果我 select 只有一个 属性 即
,上面的代码工作正常
query.select('username');
但是有多个 select 它抛出 412 'Precondition Failed' 错误。我的实体如下所示:
Entity properties
您需要创建一个 multi-property 索引才能使用 multi-property 查询。
因为您没有使用 App Engine,所以需要手动创建这些索引。
我有一个教程 here 涵盖了这个。
步骤如下:
- 安装Java 7 Runtime(或更高版本)http://java.com/
- 我建议使用 Cloud Shell,它已经安装并配置了 Java
- 创建一个名为 WEB-INF
的文件夹
- 在该文件夹中,您需要三个文件:
- appengine-web.xml(将 YOUR_PROJECT_ID_HERE 替换为您的项目 ID)
- web.xml
- datastore-indexes.xml(删除我用于示例的索引)
- 在 datastore-indexes.xml 文件中,您需要定义 multi-property 索引。 Follow the documentation.
- 安装 gcd tool
- 最后,运行 gcd工具(WEB-INF文件夹上面的一个目录)
- Linux/Mac
path/to/gcd.sh updateindexes --auth_mode=oauth2 .
- Windows
path/to/gcd.cmd updateindexes --auth_mode=oauth2 .
几分钟后,应该会创建索引。
我正在使用以下查询从 google 数据存储中检索一些实体:
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);
}
});
如果我 select 只有一个 属性 即
,上面的代码工作正常query.select('username');
但是有多个 select 它抛出 412 'Precondition Failed' 错误。我的实体如下所示: Entity properties
您需要创建一个 multi-property 索引才能使用 multi-property 查询。
因为您没有使用 App Engine,所以需要手动创建这些索引。
我有一个教程 here 涵盖了这个。
步骤如下:
- 安装Java 7 Runtime(或更高版本)http://java.com/
- 我建议使用 Cloud Shell,它已经安装并配置了 Java
- 创建一个名为 WEB-INF 的文件夹
- 在该文件夹中,您需要三个文件:
- appengine-web.xml(将 YOUR_PROJECT_ID_HERE 替换为您的项目 ID)
- web.xml
- datastore-indexes.xml(删除我用于示例的索引)
- 在 datastore-indexes.xml 文件中,您需要定义 multi-property 索引。 Follow the documentation.
- 安装 gcd tool
- 最后,运行 gcd工具(WEB-INF文件夹上面的一个目录)
- Linux/Mac
path/to/gcd.sh updateindexes --auth_mode=oauth2 .
- Windows
path/to/gcd.cmd updateindexes --auth_mode=oauth2 .
- Linux/Mac
几分钟后,应该会创建索引。