如何使用电子邮件地址查询App Engine数据存储?

huangapple go评论91阅读模式
英文:

How do I query an appengine datastore with an email address

问题

我正在尝试使用电子邮件地址在appengine datastore中查找用户。我正在使用Go语言。

这段代码找不到用户。

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

如果我将查询更改为使用"Id"属性查找用户,它可以正常工作。

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

我已确认"AccountEmail"属性的名称和值是正确的。"AccountEmail"也已经建立了索引。

是否需要对电子邮件地址进行特殊格式化才能使查询正常工作?

英文:

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

得分: 2

为了通过电子邮件(AccountEmail)找到用户,必须满足以下所有条件。请检查并确保每个“测试”都通过:

  • 必须存在一个具有属性名称AccountEmail的实体。请注意,属性名称区分大小写。请注意,数据存储名称和struct字段名称可能不同,可以使用标签进行更改,例如:

    <code>AccountEmail string \datastore:"email"``

  • 该属性必须被索引。请注意,属性是否被索引可能因实体而异,因此您可能有一个实体其中AccountEmail被索引,而另一个实体中AccountEmail未被索引。

  • AccountEmail必须具有类型string。我假设这是微不足道的,并且是这样的。但请注意,可能会保存与string类型不同的User类型的属性,例如,当您在Datastore查看器中列出实体时,电子邮件将显示为电子邮件字符串,但显然它们是不同的。

  • 要找到AccountEmail="email@address.com"的用户,保存的值必须完全是"email@address.com"。大小写字母是不同的!空格(以及所有空白字符)是有关系的!请检查保存的值是否完全是这样,因为例如在打印时您将看不到尾随空格,但它们将导致不匹配!此外,一些Unicode字符具有相同的视觉外观(它们看起来相同),但它们的Unicode代码点不同,也会导致不匹配。

英文:

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.

    <code>AccountEmail string `datastore:"email"`</code>

  • 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=&quot;email@address.com&quot;, the value saved must be &quot;email@address.com&quot; 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.

huangapple
  • 本文由 发表于 2015年3月19日 05:29:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/29133079.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定