dongleman4760 2015-03-18 21:29
浏览 21
已采纳

如何使用电子邮件地址查询Appengine数据存储区

I am trying to lookup users in appengine datastore using their email address. I'm using Go.

This code finds no users.

var users []entity.User
q := datastore.NewQuery("users").Filter("AccountEmail =", "email@address.com")
_, err := q.GetAll(c, &users)

If I change the query to lookup the user with the "Id" property instead it works fine.

var users []entity.User
q := datastore.NewQuery("users").Filter("Id", "185804764220139124118")
_, err := q.GetAll(c, &users)

I've confirmed the property name and value for "AccountEmail" is correct. "AccountEmail" It is indexed too.

Is there some special formatting that needs to be done with an email address to get the query to work?

  • 写回答

1条回答 默认 最新

  • douzhuangna6906 2015-03-19 08:28
    关注

    In order to find the user by email (AccountEmail), all of the following conditions must be true. Please check and ensure each "test" passes:

    • An entity with property name AccountEmail must exists. Don't forget that the property name is case-sensitive. Note that the datastore name and the struct field name may be different, tags can be used to change it, e.g.

      AccountEmail string `datastore:"email"`

    • The property must be indexed. Note that whether a property is indexed may vary from entity to entity, so you may have an entity where AccountEmail is indexed and another one where AccountEmail is not indexed.

    • AccountEmail must have a type string. I assume this is trivial and is so. But note that it is possible to save a property with the User type which is different from the string type and when you list entities in the Datastore viewer for example, the email will be displayed just like if it would be an email string, but obviously it is different.

    • To find the user with AccountEmail="email@address.com", the value saved must be "email@address.com" exactly. Lower and upper case letters are different! Spaces (and all whitespace characters) matter! Please check if the saved value is exactly this as you will not see trailing spaces when printed for example, but they will cause a mismatch! Also some unicode characters have the same visual appearance (they look the same) but their unicode codepoint is not the same and will also cause a mismatch.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)