dongtou5557 2016-12-11 16:22
浏览 50
已采纳

Golang Rethinkdb嵌套过滤器

I am trying to run a filter on a property of a nested object for RethinkDB in Golang. But I am sure that I am missing something here.

This is the error I am getting:

(func literal).Eq undefined (type func(gorethink.Term) gorethink.Term has no field or method Eq)

Here is my code:

type User struct {
    Id        string `json:"id,omitempty"`
    FirstName string `json:"firstName,omitempty"`
    LastName  string `json:"lastName,omitempty"`
    Email     string `json:"email,omitempty"`
    Password  string `json:"password,omitempty"`
    Salt      string `json:"salt,omitempty"`
}

type UnverifiedUserRequest struct {
    Id    string `json:"id,omitempty"`
    Token string `json:"token,omitempty"`
    User  User   `json:"user,omitempty"`
}

db.Table("unverified_requests").Filter(func(row r.Term) r.Term {
    return row.Field("user").Map(func(user r.Term) r.Term {
        return user.Field("email")
    }.Eq(email))
}).Run(session)

UPDATE 1

After making changes as suggested by @icza, the program builds fine. But I am getting the following error at runtime:

gorethink: Cannot convert OBJECT to SEQUENCE in: r.DB("uc_dev").Table("unverified_requests").Filter(func(var_‌​5 r.Term) r.Term { return var_5.Field("user").Map(func(var_6 r.Term) r.Term { return var_6.Field("email") }).Eq("myemail@gmail.com") })

  • 写回答

1条回答 默认 最新

  • doubi6303 2016-12-11 20:17
    关注

    A misplaced parenthesis. Instead of }.Eq(email)) use }).Eq(email):

    db.Table("unverified_requests").Filter(func(row r.Term) r.Term {
        return row.Field("user").Map(func(user r.Term) r.Term {
            return user.Field("email")
        }).Eq(email)
    }).Run(session)
    

    You tried to call Eq() on the function literal argument that is passed to Map(). It is obviously not of type gorethink.Term, but the return value of gorethink.Map() is, so call Eq() on the reutrn value of Map(), which means put the .Eq() after the parenthesis that closes the method call Map().

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

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?