Search code examples
rethinkdbrethinkdb-javascriptreql

.getField() returning empty result


Using the RethinkdbDash package for Node.js and Rethink, I'm able to use this ReQL:

r.db('<DATABASE>').table('<TABLE>').get('<UUID_FOR_OBJECT>')

...to get the desired object out of the database with the following format...

{
    "address":  "<ADDRESS>" ,
    "createdAt": Thu Sep 15 2016 02:08:54 GMT+00:00 ,
    "email": <EMAIL>,
    "firstName":  "<FIRST NAME>" ,
    "fullName":  "<FULL NAME>" ,
    "lastName":  "<LAST NAME>" ,
    "middleName":  "<MIDDLE NAME>" ,
    "phone":  "<PHONE NUMBER>" ,
    "prescriptions": [
     {
        "expiresOn": Thu Sep 15 2016 00:00:00 GMT+00:00 ,
        "hasExpired": false ,
        "name":  "<MEDICATION NAME>" ,
        "prescribedBy":  "<DOCTOR NAME>" ,
        "prescribedOn": Thu Sep 15 2016 02:54:52 GMT+00:00 ,
        "startOn": Thu Sep 15 2016 02:54:52 GMT+00:00 ,
        "uuid":  "f11fed84-30dc-4cf9-af36-b715f303bed1"
      }
    ] ,
    "uuid":  "bd4d6d44-3af3-4224-afef-d7e9a876025b"
}

The problem comes when I try to add the pluck or getField function to the query to isolate and retrieve just the 'prescriptions' array. This is the function in my controller for the call...

export function all(req, res) {
  let id = req.params.id

  r.table('Patients').get(id).pluck('prescriptions').run() //Also tried .getField('prescriptions') and .get(id)('prescriptions')
    .then((results) => {
      console.log(results)
      return res.json({ status: 200, data: results })
    })
    .catch((error) => {
      console.log(error)
      return res.json({ status: 400, message: 'There was an error finding the medication of patient ' + id, data: error })
    })
}

When I call the API path the access this data and execute the all function, I get the following response...

{
    status: 200,
    data: []
}

The exact same query, however, works as expected within the Rethink admin console's data explorer.

Any idea or help as to why this is happening is greatly appreciated!


Solution

  • Problem solved.

    Issue was actually with my routes specified with Express and nothing to do with rethinkdb!