我正在使用以下查询从 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);
}
});
如果我只选择一个属性,上面的代码工作正常,即
query.select('username');
但是使用多重选择会抛出 412“前提条件失败”错误。我的实体如下所示: Entity properties
最佳答案
您需要创建多属性索引才能使用多属性查询。
由于您没有使用 App Engine,因此需要手动创建这些索引。
我有一个教程here这涵盖了这一点。
步骤如下:
- 安装 Java 7 运行时(或更高版本)http://java.com/
- 我建议使用Cloud Shell已经安装并配置了 Java
- 创建一个名为 WEB-INF 的文件夹
- 在该文件夹中,您需要三个文件:
- appengine-web.xml (将 YOUR_PROJECT_ID_HERE 替换为您的项目 ID)
- web.xml
- datastore-indexes.xml (删除我用于示例的索引)
- 在 datastore-indexes.xml 文件中,您需要定义多属性索引。 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
几分钟后,您的索引就会创建完毕。
关于javascript - 谷歌数据存储查询中的多项选择抛出 ApiError : Precondition Failed error in node,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34928582/