RethinkDB - Updating nested array

后端 未结 6 1243
深忆病人
深忆病人 2021-02-13 01:42

I have a survey table that looks like so:

{
  id: Id,
  date: Date,
  clients: [{
    client_id: Id,
    contacts: [{
      contact_id: Id,
      score: Number,
         


        
6条回答
  •  终归单人心
    2021-02-13 02:25

    database schema

    {
      "clients": [
        {
          "name":  "jacob" ,
          "score": 200
        } ,
        {
          "name":  "jorge" ,
          "score": 57
        }
      ] ,
      "id":  "70589f08-284c-495a-b089-005812ec589f"
    }
    

    then you can do like this using map and branch query .

    r.db('users').table('participants').get('70589f08-284c-495a-b089-005812ec589f')
      .update({"clients": r.row('clients').map(function(elem){
         return r.branch(
          elem('name').eq("jacob"),
          elem.merge({ "score": 100 }),
          elem)})
        })
    

提交回复
热议问题