0
{
  "LOGIN": "ABC",
  "MESSAGE_UNPROCESSED": [
    {
      "DATE": "20160219",
      "MESSAGE": [
        {
          "address": "XYZ",
          "date": "1468385398746"
        },
        {
          "address": "PQR",
          "date": "1468385398746"
        }
      ]
    },
    {
      "DATE": "20160220",
      "MESSAGE": [
        {
          "address": "LMN",
          "date": "1468385398746"
        },
        {
          "address": "JXT",
          "date": "1468385398746"
        }
      ]
    }
  ],
  "id": "e1705cae-2a57-42b3-af2e-8458ae9a43bb"
}

I want to add message into the field where Login is ABC if DATE doesn't exist or if it exist I want to replace the entire object from doc

I tried this :

r.db('usersData').table('smsRaw').filter(function (row) {
    return row('MESSAGE_UNPROCESSED')('DATE').contains('20160222').replace({"DUMP":"DUMP"})
})

error: Cannot nest writes or meta ops in stream operations.  Use FOR_EACH instead in:
r.db("usersData").table("smsRaw").filter(function(var_13) {
    return var_13("MESSAGE_UNPROCESSED")("DATE").contains("20160222").replace({"DUMP": "DUMP"}); 
})

so if records {"DATE":"2016018","MESSAGE":[{"address":"abc","Date":"121212"}]} if this record doesn't exist in MESSAGE_UNPROCESSED it should be added using set_insert or else if date is existing like 2016020 then entire element from array should be replaced

r.db('usersData').table('smsRaw').get("7cd66671-bb01-483d-a148-12ed1b7c2d31").update(function(row) {
    return {
        MESSAGE_UNPROCESSED: r.branch(
            row("MESSAGE_UNPROCESSED")('DATE').eq('20160222'),
            row("MESSAGE_UNPROCESSED")('MESSAGE').merge({"DUMP":"DUMP"}),
            row("MESSAGE_UNPROCESSED")('MESSAGE').replace({"NEW":"NEW"})
        )
    }
})         

Cannot nest writes

I want to do this manipulation using python

ArK
  • 20,698
  • 67
  • 109
  • 136
Vinay Sawant
  • 368
  • 2
  • 7
  • 23
  • r.db('usersData').table('smsRaw').get(id).filter(function (row){return row('MESSAGE_UNPROCESSED')('DATE').contains('20160222')}) .replace(Document)) – Vinay Sawant Jul 25 '16 at 07:56
  • 1
    put this code in the question's body and write what did you get as a result and what did you expect/ – spirit Jul 25 '16 at 07:58

0 Answers0