How to delete elements in an array using RethinkDB


Datsik:

I have a table that Lobbysactually contains party rooms, it has an array of Members and an array of Messages, here 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": [ ]
}

Now when the user's websocket connects to Lobbyit, it will add their username to the Memberslist, and I am trying to do this so that when the user leaves Partyit, it is removed from the member list , 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 got 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 apparently there is a bug, I'm new to Rethink so I'm not sure exactly what to do, unless I should select the array, modify it myself, and put back the new array.

Right now, I'm currently using this solution, but I feel like it might be simpler, especially if I can have it ReQLmodify the array instead of doing it manually

This is my current solution, not related to the problem

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,
})
Lucy:

You probably want something like this:

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

Related


How to delete elements in an array using RethinkDB

Datsik: I have a table that Lobbysactually contains party rooms, it has an array of Members and an array of Messages, here is an example: { "id": "a77be9ff-e10f-41c1-8a4c-66b5a55d823c" , "members": [ "Gacnt" , "Gacnt" , "Gacnt" , "Gacnt" , "Gacnt" , "Gacnt" ,

How to delete elements in an array using RethinkDB

Datsik: I have a table that Lobbysactually contains party rooms, it has an array of Members and an array of Messages, here is an example: { "id": "a77be9ff-e10f-41c1-8a4c-66b5a55d823c" , "members": [ "Gacnt" , "Gacnt" , "Gacnt" , "Gacnt" , "Gacnt" , "Gacnt" ,

How to delete elements in an array using RethinkDB

Datsik: I have a table that Lobbysactually contains party rooms, it has an array of Members and an array of Messages, here is an example: { "id": "a77be9ff-e10f-41c1-8a4c-66b5a55d823c" , "members": [ "Gacnt" , "Gacnt" , "Gacnt" , "Gacnt" , "Gacnt" , "Gacnt" ,

How to delete elements in an array using RethinkDB

Dazik I have a table that Lobbysactually contains party rooms, it has an array of Members and an array of Messages, here is an example: { "id": "a77be9ff-e10f-41c1-8a4c-66b5a55d823c" , "members": [ "Gacnt" , "Gacnt" , "Gacnt" , "Gacnt" , "Gacnt" , "Gacnt" , "

How to delete a specific object in an array in RethinkDB

Mint I just want to learn RethinkDB. I am a little confused how to delete a single object in an array, what is the exact query I have to use if I have to delete this object { "name": "Ram" , "username": "B97bf210-c4d2d-11e6-b783-07b5fev04870

How to delete an array of elements in an array

daffodils I have two arrays. I want to delete if the second array exists in the first array. E.g array1 = array ("apple","banana","papaya","watermelon","avocado"); array2 = array ("apple","avocado"); I expect the output should be Array ( [1] => banana [2] =>

How to delete an array of elements in an array

daffodils I have two arrays. I want to delete if the second array exists in the first array. E.g array1 = array ("apple","banana","papaya","watermelon","avocado"); array2 = array ("apple","avocado"); I expect the output should be Array ( [1] => banana [2] =>

How to delete an array of elements in an array

daffodils I have two arrays. I want to delete if the second array exists in the first array. E.g array1 = array ("apple","banana","papaya","watermelon","avocado"); array2 = array ("apple","avocado"); I expect the output should be Array ( [1] => banana [2] =>

How to delete data from RethinkDB database using its changefeed

Kurt Peek I'm working on a "controller" for a database that is constantly producing data, but only using the most recent data defined as less than 3 days old. Once the data expires more than 3 days, I want to dump it to a JSON file and delete it from the datab

How to delete array elements in mongodb?

Justin John This is the array structure contact: { phone: [ { number: "+1786543589455", place: "New Jersey", createdAt: "" } { number: "+1986543589455", place: "Houston",

How to delete array elements in mongodb?

Justin John This is the array structure contact: { phone: [ { number: "+1786543589455", place: "New Jersey", createdAt: "" } { number: "+1986543589455", place: "Houston",

how to delete elements in mongodb array

username How can I delete an element of an array in a collection like this: { "_id" : "Y9BBFa4c4vMiAkjbi", "metadata" : { "tags" : [ "Anything", "Something", "More" ] } } In this example I only w

how to delete elements in mongodb array

username How can I delete an element of an array in a collection like this: { "_id" : "Y9BBFa4c4vMiAkjbi", "metadata" : { "tags" : [ "Anything", "Something", "More" ] } } In this example I only w

How to delete array elements in mongodb?

Justin John This is the array structure contact: { phone: [ { number: "+1786543589455", place: "New Jersey", createdAt: "" } { number: "+1986543589455", place: "Houston",

how to delete elements in mongodb array

username How can I delete an element of an array in a collection like this: { "_id" : "Y9BBFa4c4vMiAkjbi", "metadata" : { "tags" : [ "Anything", "Something", "More" ] } } In this example I only w