How to remove an element in an array using RethinkDB

I have a table containing Lobbyswhich are essentially Party Rooms, it has an array of Members and an array of messages, this is an example:

{
"id":  "a77be9ff-e10f-41c1-8a4c-66b5a55d823c" ,
"members": [
"Gacnt" ,
"Gacnt" ,
"Gacnt" ,
"Gacnt" ,
"Gacnt" ,
"Gacnt" ,
"Gacnt" ,
"Gacnt" ,
"Gacnt" ,
"Gacnt" ,
"Gacnt" ,
"Gacnt" ,
"Gacnt" ,
"Gacnt" ,
"Gacnt" ,
"Gacnt" ,
"Gacnt" ,
"Gacnt" ,
"Gacnt" ,
"Gacnt" ,
"Gacnt" ,
"Gacnt"
] ,
"messages": [ ]
}

Right now, when the user’s website connects to Lobby, he will add his username to the list Members, and I am trying to make sure that when the user leaves Party, he removes them from the list of participants, I came up with this:

r.db("gofinder").table("Lobbys").get("a77be9ff-e10f-41c1-8a4c-66b5a55d823c")("members").update({
  members: r.db("gofinder").table("Lobbys").get("a77be9ff-e10f-41c1-8a4c-66b5a55d823c")("members").ne("Gacnt")
})

But I get the error:

e: Could not prove argument deterministic.  Maybe you want to use the non_atomic flag? in:
r.db("gofinder").table("Lobbys").get("a77be9ff-e10f-41c1-8a4c-66b5a55d823c")("members").update({"members": r.db("gofinder").table("Lobbys").get("a77be9ff-e10f-41c1-8a4c-66b5a55d823c")("members").ne("Gacnt")})
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

But obviously there is a mistake, I'm new to Rethink, so I'm not sure exactly how to do this, unless I have to select the array, change it myself, and then turn on the new array again.

, , , ReQL ,

query = gorethink.Table("Lobbys").Get(userinfo.LobbyID).Field("members")
res, err := query.Run(db)
if err != nil {
    log.Println(err)
}
defer res.Close()
var members []string
if err = res.All(&members); err != nil {
    log.Println(err)
}

for i := 0; i < len(members); i++ {
    if members[i] == userinfo.Username {
        members = append(members[:i], members[i+1:]...)
        i--
    }
}

query = gorethink.Table("Lobbys").Get(userinfo.LobbyID).Update(map[string]interface{}{
    "members": members,
})
+4
1

, - :

r.db('gofinder').table('Lobbys').get(ID).update(function(row) {
  return {members: row('members').setDifference(['Gacnt'])};
})
+6

Source: https://habr.com/ru/post/1622568/


All Articles