douyan8267 2016-08-08 12:38
浏览 21
已采纳

带有过滤器的AppEngine数据存储区查询从不返回结果(Go)

If I don't use a filter, I get results. If I use a filter (this record definitely exists), I don't get any results. It might be the lack of an index defined for that property, but, as I understand it, simple indices should automatically be created in the development server (and an index.yaml file created and populated with it). This is not happening.

query = datastore.NewQuery("UserAccount").Filter("email =", "test@example.com")

ua := UserAccount{}
t := query.Run(ctx)
for ; ; {
    if _, err = t.Next(&ua); err == nil {
        log.Debugf(ctx, "Current: %s", ua)
    } else if err == datastore.Done {
        break
    } else {
        panic(err)
    }
}

When the development server terminates, it states that it's "saving search indexes":

INFO     2016-08-08 05:09:52,894 api_server.py:651] Saving search indexes

However, since an "index.yaml" file doesn't appear, I'm assuming that no indices needed to be created, which means that my query must not've had the desired effect?

What am I missing?

Edit:

Note that the record was previously created and the application stopped and started many times since. I sincerely doubt this is a eventual-consistency thing.

Edit 2:

For the purpose of testing, I've created the following model with the following code. They both exhibit the same behavior as my original model and code.

Definition:

type TestEntity struct {
    Email string
}

Code:

log.Debugf(ctx, "Putting.")

email := "anothertest@a.b"

te := &TestEntity{
        Email: email,
}

k := datastore.NewKey(ctx, "TestEntity", "123", 0, nil)
_, err = datastore.Put(ctx, k, te)
if err != nil {
    panic(err)
}

log.Debugf(ctx, "Waiting.")
time.Sleep(1 * time.Second)

query := datastore.NewQuery("TestEntity")

var results []TestEntity
_, err = query.GetAll(ctx, &results)
log.Debugf(ctx, "GetAll: %s", results)

log.Debugf(ctx, "Running query.")

query = datastore.NewQuery("TestEntity").Filter("email =", email)

te = &TestEntity{}
t := query.Run(ctx)
for ; ; {
    if _, err = t.Next(te); err == nil {
        log.Debugf(ctx, "Found: [%s]", te.Email)
    } else if err == datastore.Done {
        log.Debugf(ctx, "Done.")
        break
    } else {
        panic(err)
    }
}

Results:

2016/08/09 02:11:36 DEBUG: Putting.
2016/08/09 02:11:36 DEBUG: Waiting.
2016/08/09 02:11:37 DEBUG: GetAll: [{anothertest@a.b}]
2016/08/09 02:11:37 DEBUG: Running query.
2016/08/09 02:11:37 DEBUG: Done.

Screenshot of Viewer:

Screenshot of Viewer

  • 写回答

2条回答 默认 最新

  • douchi7073 2016-08-09 05:41
    关注

    The property name in the datastore is "Email" with capital E, not "email".

    It's case-sensitive, must be queried with capital E:

    query = datastore.NewQuery("UserAccount").Filter("Email =", "test@example.com")
    

    If you would want it to be saved / retrieved with small e, you could use tags to do the mapping, e.g.:

    type UserAccount struct {
        Email string `datastore:"email"`
        // other fields...
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 什么设备可以研究OFDM的60GHz毫米波信道模型
  • ¥15 不知道是该怎么引用多个函数片段
  • ¥15 爬取1-112页所有帖子的标题但是12页后要登录后才能 我使用selenium模拟登录 账号密码输入后 会报错 不知道怎么弄了
  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题