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().

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

报告相同问题?

悬赏问题

  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写