当我尝试按日期对数据存储运行查询时,我会收到以下错误提示:
如果不尝试按日期排序,则查询会无错误运行。在数据存储索引下,应用程序引擎控制台显示:
NeedIndexError: no matching index found.
The suggested index for this query is:
- kind: Message
properties:
- name: author
- name: ref
- name: date
如果不尝试按日期排序,则查询会无错误运行。在数据存储索引下,应用程序引擎控制台显示:
author ▲ , ref ▲ , date ▼
Serving
我做错了什么?如何按日期排序运行我的查询?谢谢!
以下是我的实体定义:
from google.appengine.ext import ndb
class Message(ndb.Model):
subject = ndb.StringProperty()
body = ndb.TextProperty()
date = ndb.DateTimeProperty(auto_now_add=True)
ref = ndb.StringProperty( required=True )
author = ndb.KeyProperty(required=True)
这是失败的查询语句:
def readMessages( ref, user = None ):
query = Message.query()
query = query.filter(Message.ref == ref )
if user:
query = query.filter(Message.author == user.key )
query = query.order(Message.date)
# convert to a list so we can index like an array
return [ message for message in query ]
我的index.yaml包含以下内容:
indexes:
- kind: Message
properties:
- name: author
- name: ref
- name: date
direction: desc