通过不在 Google App Engine php 中工作来订购

order by not working in Google App Engine php

我在 PHP 中使用了 Google App Engine 和 ndb

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

$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

获取带有订单 desc 的数据

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

创建一个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