我正在将Dart的client-server example部署到我的Google应用程序引擎中。数据可以很好地插入到云数据存储中。但是,当查询数据时,每当我发出GET请求来查询所有数据时,就会发生以下异常。
13:04:19.191 Uncaught error in request handler: An index is needed for the query to succeed.
#0 catchAndReThrowDatastoreException.<anonymous closure> (package:appengine/src/api_impl/raw_datastore_v3_impl.dart:48:5)
#1 _rootRunBinary (dart:async/zone.dart:914)
#2 _CustomZone.runBinary (dart:async/zone.dart:812)
#3 _Future._propagateToListeners.handleError
...
我做了一些digging,发现我可以使用运算符为对象插入索引。
所以我的数据存储对象现在是以下内容:
import 'package:gcloud/db.dart';
@Kind()
class Item extends Model {
@StringProperty()
String name;
operator [](index) => name[index];
Map serialize() => {'name': name};
static Item deserialize(Map json) => new Item()..name = json['name'];
}
但是,当我发出查询所有数据的get请求时,仍然会抛出相同的异常。
有什么建议么?
最佳答案
我假设您的deploy命令中缺少index.yaml
文件
gcloud preview app deploy app.yaml index.yaml
它在此处以蓝色框突出显示,但我也第一次错过了它:
https://www.dartlang.org/server/google-cloud-platform/app-engine/deploy.html
关于google-app-engine - Dart-为Google Cloud Datastore的dart数据存储对象插入索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28419710/