nodesto
nodesto

Reputation: 505

Chain RethinkDB filtering with document manipulation

I am trying the following with RethinkDB (NodeJS driver):

const cursor = await r.table('users')
  .filter({ 'username': friendRequest.initiator })
  .getField(friends)
  .append(friendRequest.target)
  .run(conn)

But I get the error stating Expected type DATUM but found SEQUENCE.

How do I first filter and then manipulate documents?

Upvotes: 0

Views: 71

Answers (1)

r.table('users')
  .filter({ 'username': friendRequest.initiator })

returns array, but getField only works for objects.

As I can see, you want to filter users and get filed "friends" and append new record to it. You should use pluck for this and after use map on the result:

const cursor = await r.table('users')
  .filter({ 'username': friendRequest.initiator })
  .pluck(friends)
  .map(function(row){
     return row(friends).append(friendRequest.target);
  })      
  .run(conn)

Upvotes: 1

Related Questions