0

I'm building a database with rethinkdb and koajs. Is there anyway in Reql to only deliver a specific field within a filter function? here is my code:

function bySwimmer() {
    return function *(next) {

      var qs = this.request.querystring;
      var q = this.request.query;

      //pulls data from the db
      var cursor = yield r.table('swim').filter(function(swim) {

        //if there is no query it will return all data else returns only the data specified by the query
        if(qs == "") {
          return swim.getField("fullName");
        } else {
          return swim('fullName').upcase().eq(q.fullname.toUpperCase());
        }

      }).run(this._rdbConn);
      var result = yield cursor.toArray();
      this.body = JSON.stringify(result);

      yield next
    }
}

getField() should only return that field but all the data is still sent to the browser.

James Moore
  • 1,881
  • 14
  • 18

1 Answers1

1

The filter command only determines what rows are returned, it does not let you change them. You can you .map or just () to modify the returned rows. For example:

var query = r.table('swim');

if(qs == "") {
  query = query('fullName');
} else {
  query = query.filter(function(swim) {
    swim('fullName').upcase().eq(q.fullname.toUpperCase())
  });
}

var cursor = yield query.run(this._rdbConn);
Etienne Laurin
  • 6,731
  • 2
  • 27
  • 31