带有 .order returns 错误 412 'Precondition Failed' 的 Gcloud 数据存储 runQuery
Gcloud Datastore runQuery with .order returns error 412 'Precondition Failed'
我正在使用 Google 节点 JS 上的云平台数据存储开发应用程序。使用 Book Shelf 示例中的部分代码。
当我在带有 .filter() 的 runQuery 方法中使用 .order() 时出现的问题 returns 代码 412 错误 - 'Precondition Failed'。当我在没有 .order() 或 .filter() 的情况下这样做时,效果很好。我做错了什么?
在下面的代码中:list() 有效; readByQuery() 没有。
function list(limit, token, cb) {
var q = ds.createQuery(namespace, kind)
.limit(limit)
.order(config.order)
.start(token);
ds.runQuery(q, function (err, entities, cursor) {
if (err) {
return cb(err);
}
var hasMore = entities.length === limit ? cursor : false;
cb(null, entities.map(fromDatastore), hasMore);
});
}
function readByQuery(key, operator, value, limit, token, cb) {
var q = ds.createQuery(namespace, kind)
.filter(key+ ' ' + operator, value)
.order(config.order)
.limit(limit)
.start(token);
ds.runQuery(q, function (err, entities) {
if (err) {
console.log(err);
return cb(err);
}
cb(null, entities.map(fromDatastore));
});
}
方法 readByQuery() returns:
[ApiError: Precondition Failed]
errors: [],
code: 412,
message: 'Precondition Failed'
谢谢
您 运行 遇到了典型的数据存储限制,有详细记录,例如 https://cloud.google.com/appengine/docs/go/datastore/queries :
Note: Because of the way the App Engine Datastore executes queries, if a query specifies inequality filters on a property and sort orders on other properties, the property used in the inequality filters must be ordered before the other properties.
因此key
、operator
和config.order
相互强烈约束:具体来说,如果运算符是不等式,则config.order
和key
必须 相同——并且您的代码中没有任何内容检查这一点。
我正在使用 Google 节点 JS 上的云平台数据存储开发应用程序。使用 Book Shelf 示例中的部分代码。
当我在带有 .filter() 的 runQuery 方法中使用 .order() 时出现的问题 returns 代码 412 错误 - 'Precondition Failed'。当我在没有 .order() 或 .filter() 的情况下这样做时,效果很好。我做错了什么?
在下面的代码中:list() 有效; readByQuery() 没有。
function list(limit, token, cb) {
var q = ds.createQuery(namespace, kind)
.limit(limit)
.order(config.order)
.start(token);
ds.runQuery(q, function (err, entities, cursor) {
if (err) {
return cb(err);
}
var hasMore = entities.length === limit ? cursor : false;
cb(null, entities.map(fromDatastore), hasMore);
});
}
function readByQuery(key, operator, value, limit, token, cb) {
var q = ds.createQuery(namespace, kind)
.filter(key+ ' ' + operator, value)
.order(config.order)
.limit(limit)
.start(token);
ds.runQuery(q, function (err, entities) {
if (err) {
console.log(err);
return cb(err);
}
cb(null, entities.map(fromDatastore));
});
}
方法 readByQuery() returns:
[ApiError: Precondition Failed]
errors: [],
code: 412,
message: 'Precondition Failed'
谢谢
您 运行 遇到了典型的数据存储限制,有详细记录,例如 https://cloud.google.com/appengine/docs/go/datastore/queries :
Note: Because of the way the App Engine Datastore executes queries, if a query specifies inequality filters on a property and sort orders on other properties, the property used in the inequality filters must be ordered before the other properties.
因此key
、operator
和config.order
相互强烈约束:具体来说,如果运算符是不等式,则config.order
和key
必须 相同——并且您的代码中没有任何内容检查这一点。