1

I have following table structure -

{
  "id": 1,
  "prop": {
    "1": {
      "bunch-of-stuffs": "foo"
    },
    "2": {
      "bunch-of-stuffs": "bar"
    }
  }
}

I want to remove "prop" with the key "2" so that it looks like:

{
  "id": 1,
  "prop": {
    "1":{
      "bunch-of-stuffs": "foo"
    }
  }
}

I have tried the update, but it doesn't work -

r.table("sad").get(1).update({"prop":{"1":{ "bunch-of-stuffs": "foo" }}})

taygetos
  • 3,005
  • 2
  • 21
  • 29
Bopsi
  • 2,090
  • 5
  • 36
  • 58
  • Possible duplicate of [RethinkDB: Javascript - How to deleted nested objects](https://stackoverflow.com/questions/50006585/rethinkdb-javascript-how-to-deleted-nested-objects) – Virginia Dec 09 '18 at 14:30

1 Answers1

0

In your particular case you can simply call the .replace function to replace the whole document as you know every value:

r.table("sad").get(1).replace({
 "id":1,
 "prop":{
    "1":{ "bunch-of-stuffs": "foo" }
  }
})

If you know the id of the "prop" that you want to delete, you can use the replace like follows, to avoid sending the whole json document over the wire:

r.table("sad").get(1).replace(function(doc){
      return {"id":1, "prop": doc("prop").without("2")}
})
taygetos
  • 3,005
  • 2
  • 21
  • 29
  • I know that will work, but my table "sad" has almost 50 properties and I do not wish to send large json over the network to my node backend. Is there any alternative to update the document by sending information about the concerned property? – Bopsi Dec 10 '18 at 07:17
  • please check out the edit i made. Do you know the id of the prop that you want to delete ("2") ? – taygetos Dec 10 '18 at 08:29