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"
}

我想将消息添加到登录所在的字段中,ABC如果DATE不存在或者如果它存在我想从文档中替换整个对象

我试过这个:

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"}); 
})

因此,如果{"DATE":"2016018","MESSAGE":[{"address":"abc","Date":"121212"}]} 记录中不存在此记录MESSAGE_UNPROCESSED,则应使用 set_insert 添加,否则如果日期存在2016020,则应替换数组中的整个元素

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"})
        )
    }
})         

无法嵌套写入

我想用 python 做这个操作

4

0 回答 0