Google Cloud Datastore,Python客户端,add_filter不返回任何结果

时间:2018-07-31 11:45:35

标签: google-cloud-datastore

我有这样的代码,它不会打印任何内容:

from google.cloud import datastore
client = datastore.Client()
query = client.query(kind='Kind')
query.add_filter('status', '=', 'new')
results = query.fetch()

for result in results:
        print result

当我注释query.add_filter('status', '=', 'new')行时,它会按预期打印所有实体。

我的index.yaml文件是:

indexes:
- kind: Kind
  properties:
  - name: increment
  - name: status

数据存储仪表板上的状态为“正在投放”

我使用App Engine的以下代码创建实体:

class Kind(ndb.Model):
        json = ndb.TextProperty()
        status = ndb.TextProperty(indexed=True)
        increment = ndb.IntegerProperty()
        created = ndb.DateTimeProperty(auto_now_add=True)

class MainPage(webapp2.RequestHandler):
        @ndb.toplevel
        def post(self):
                parajson = self.request.get("json")
                parastatus = self.request.get("status")
                paraincrementtmp = self.request.get("id")
                print paraincrementtmp
                paraincrement = int(paraincrementtmp)
                #print parajson         

                write = Kind(json = parajson,
                        status = parastatus,
                        increment = paraincrement)
                key = write.put()

如何在第一个代码片段中使add_filter部分起作用?

0 个答案:

没有答案