Google app engine Golang-带[]字节比较的Appengine数据存储筛选查询
我试图对数据存储中的一组实体执行筛选查询,但我试图使用相等运算符查询的实体字段的类型为[]字节,我不知道appengine数据存储是否可以执行此比较 这是我的实体:Google app engine Golang-带[]字节比较的Appengine数据存储筛选查询,google-app-engine,go,filter,byte,google-cloud-datastore,Google App Engine,Go,Filter,Byte,Google Cloud Datastore,我试图对数据存储中的一组实体执行筛选查询,但我试图使用相等运算符查询的实体字段的类型为[]字节,我不知道appengine数据存储是否可以执行此比较 这是我的实体: type Data struct { Id int64 `json:"id"` Version int32 `json:"-"` HMAC []byte `json:"-"` Status string `json:"status"` } 这是我的查询逻辑 func (
type Data struct {
Id int64 `json:"id"`
Version int32 `json:"-"`
HMAC []byte `json:"-"`
Status string `json:"status"`
}
这是我的查询逻辑
func (view *DataView) GetDataByHMAC(hmac []byte) (Data, error) {
view_key := datastore.NewKey(view.context, "View", "data-view", 0, nil)
data := make([]Data, 0)
query := datastore.
NewQuery("ViewData").
Ancestor(view_key).
Filter("HMAC = ", hmac)
_, err := query.GetAll(view.context, &data)
if err != nil {
return Data{}, err
}
if len(data) == 0 {
return Data{}, ErrNoData
}
return data[0], nil
}
它会生成,但不会返回任何结果,即使在编程重试了10秒之后也是如此,因此我不认为这是数据存储和我存储在其中的视图数据之间的最终一致性问题
我的主要问题是:appengine数据存储是否允许查询在类型为[]字节的字段上使用比较过滤器?您的主要问题的答案是否,因为[]字节存储为blob,而应用程序引擎数据存储没有索引该blob
queries with a filter or sort order on the unindexed property
will never match that entity.
Note: In addition to any unindexed properties you declare explicitly,
those typed as []byte are automatically treated as unindexed.
以下是文档:在1.9.11中,数据存储包中引入了
ByteString
类型。它可用于存储简短的索引字节片
如果您将实体更改为以下内容,则该实体应能正常工作:
type Data struct {
ID int64 `json:"id"`
Version int32 `json:"-"`
HMAC datastore.ByteString `json:"-"`
Status string `json:"status"`
}
更多信息:问题是什么?很抱歉,在我花时间讨论这个问题之前,我已经明确了。请删除筛选器字符串中的尾随空格
“HMAC=“
”,然后看看会发生什么。我看不到行为有任何变化,我的所有其他查询都包括可选空格并准确返回结果;不过我没有想到要检查,谢谢。你能不能把[]字节
存储为字符串
?