How to fix index error when querying GAE datastore?

后端 未结 2 761
傲寒
傲寒 2021-01-02 11:05

When I try to run a query on the datastore ordered by date I get the following error:

NeedIndexError: no matching index found.
The suggested index for this q         


        
2条回答
  •  不知归路
    2021-01-02 11:33

    You need to specify the "direction" as well because "ordering" is done when index is written to speed things up in Google's style.

    So, your index.yaml should be like:

    indexes:
    
    - kind: Message
      properties:
      - name: author
      - name: ref
      - name: date
        direction: desc
    

    Here's Google's official description about order:

    The direction to sort, either asc for ascending or desc for descending. This is only required for properties used in sort orders of the query, and must match the direction used by the query. The default is asc.

    I hope this helps.

提交回复
热议问题