【问题标题】:order by not working in Google App Engine php通过不在 Google App Engine php 中工作来订购
【发布时间】:2020-07-05 21:21:22
【问题描述】:

我在 ndb 中使用过 Google App Enginein PHP

现在我必须将数据保存到模型并从中获取

$query = $datastore->query()
    ->kind('warehouse'); 

$result = $datastore->runQuery($query);

仓库有名称和地址字段

这个查询运行良好

当我尝试这个时

use Google\Cloud\Datastore\Query\Query;

$query = $datastore->query()
    ->kind('warehouse')->order('created', Query::ORDER_DESCENDING);
$result = $datastore->runQuery($query);

这不起作用,Name 具有 StringProperty。如何从 ndb 获取具有 order desc 的数据

https://cloud.google.com/datastore/docs/concepts/queries

【问题讨论】:

  • 从您分享的文档中我发现您还必须edit ".yaml" 文件.a

标签: php google-app-engine app-engine-ndb


【解决方案1】:

创建一个 index.yaml 文件并将这段代码放入其中

indexes:
- kind: warehouse
  ancestor: no
  properties:
  - name: created
    direction: desc

如果你想应用过滤器

 $query = $datastore->query()
 ->kind('warehouse')->filter->('address'=>'USA')->order('created', Query::ORDER_DESCENDING);

然后在 index.yaml 中

indexes:
- kind: warehouse
  ancestor: no
  properties:
  - name: address 
  - name: created
    direction: desc

然后上传

gcloud datastore indexes create index.yaml

【讨论】:

    猜你喜欢
    • 2012-10-23
    • 2016-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-25
    • 1970-01-01
    • 2015-11-19
    • 1970-01-01
    相关资源
    最近更新 更多