更新更新请求中的某些值
Update certain values in update request
我有一个通知列表,我想将其状态更新为已读
通知结构:
type Notification struct {
Id string `gorethink:"id,omitempty"`
UserId string
Content string
Read bool
CreatedAt time.Time
}
在我用来获取通知的句柄函数中,我放置了如下内容:
func getLastNotifications(w http.ResponseWriter, r *http.Request){
ret := notification.getLastNotification()
userId := getCurrentUserId()
go func(){
r.Table("Notifications").Filter(r.Row.Field("UserId").Eq(userId)).Update(func(term r.Term) r.Term{
//And here i would like only update each Notification with {Read: true}
})
}()
RenderJSON(http.StatusOK, ret)
}
如代码中所述,我希望在每个 Notification[=26= 中将 Read 更新为 true ] 属于用户。
那我该怎么做呢?
谢谢
您应该能够使用以下查询更新所有用户帖子以阅读:
r.Table("Notifications").Filter(r.Row.Field("UserId").Eq(userId)).Update(map[string]interface{}{"read": false})
希望对您有所帮助!
我有一个通知列表,我想将其状态更新为已读
通知结构:
type Notification struct {
Id string `gorethink:"id,omitempty"`
UserId string
Content string
Read bool
CreatedAt time.Time
}
在我用来获取通知的句柄函数中,我放置了如下内容:
func getLastNotifications(w http.ResponseWriter, r *http.Request){
ret := notification.getLastNotification()
userId := getCurrentUserId()
go func(){
r.Table("Notifications").Filter(r.Row.Field("UserId").Eq(userId)).Update(func(term r.Term) r.Term{
//And here i would like only update each Notification with {Read: true}
})
}()
RenderJSON(http.StatusOK, ret)
}
如代码中所述,我希望在每个 Notification[=26= 中将 Read 更新为 true ] 属于用户。
那我该怎么做呢? 谢谢
您应该能够使用以下查询更新所有用户帖子以阅读:
r.Table("Notifications").Filter(r.Row.Field("UserId").Eq(userId)).Update(map[string]interface{}{"read": false})
希望对您有所帮助!