camccar
camccar

Reputation: 730

Rethink DB Query for sub array only

Lets say I have an object in a table called alerts like

{ id:"1"
   history:[ {
            date:"some date"
            hid:"1234"
          },
         { 
          date:"some date"
          hid:"1234"
         }
       ]
  }
 { id:"2"
   history:[ {
            date:"some other date"
            hid:"1235"
          },
         { 
          date:"some date"
          hid:"1234"
         }
       ]
  }

I want an array of just the history objects from all alerts. If I use pluck such as

r.db("irrelevant").table("alerts").pluck("history")

I end up with the whole structure with brackets just no id. like

{
  history:[{hid:123,date:"some date"}{hid:123,date:"some date"}]
},
{
  history:[{hid:123,date:"some date"}{hid:123,date:"some date"}]
 }

When what I want is

[{hid:123,date:"some date"},{hid:123,date:"some date"},{hid:123,date:"some date"},{hid:123,date:"some date"}]

I'm specifically doing this in go but if I can find a RethinkDB javascript query I could probably translate it into go

Upvotes: 0

Views: 78

Answers (1)

inf581
inf581

Reputation: 642

You need to use concatMap command

r.db("irrelevant").table("alerts").concatMap(r.row.getField('history'))

Upvotes: 1

Related Questions