英文:
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 thestruct
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 whereAccountEmail
is not indexed. -
AccountEmail
must have a typestring
. I assume this is trivial and is so. But note that it is possible to save a property with theUser
type which is different from thestring
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论