如何使用电子邮件地址查询appengine数据存储 [英] How do I query an appengine datastore with an email address

查看:138
本文介绍了如何使用电子邮件地址查询appengine数据存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用他们的电子邮件地址在appengine数据存储中查找用户。

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

如果我更改查询以查找带有Id属性,而不是它的工作正常。

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

我已确认AccountEmail的属性名称和值是正确的。 AccountEmail也被索引。



是否需要使用电子邮件地址进行特殊格式化才能使查询生效?

解决方案

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


  • 具有属性名称 AccountEmail 必须存在。不要忘记属性名称区分大小写。请注意,数据存储区名称和 struct 字段名称可能不同,可以使用标签更改它,例如

    AccountEmail字符串`datastore:email`


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


  • AccountEmail 必须有一个类型字符串。我认为这是微不足道的,是如此。但请注意,可以使用不同于字符串类型的 User 类型保存属性,而当您例如,在数据存储查看器中列出实体,将显示电子邮件,就好像它是电子邮件字符串一样,但显然它是不同的。

  • 具有 AccountEmail =email@address.com的用户,保存的值必须为email@address.com确切地说。大小写字母不同!空格(和所有空白字符)很重要!请检查保存的值是否正确,因为例如打印时不会看到尾部空格,但会造成不匹配!还有一些unicode字符具有相同的视觉外观(它们看起来相同),但是它们的unicode代码点不一样,并且也会导致不匹配。

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?

解决方案

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.

这篇关于如何使用电子邮件地址查询appengine数据存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆