使用 and 的包RethinkdbDash
,我可以使用它:Node.js
Rethink
ReQL
r.db('<DATABASE>').table('<TABLE>').get('<UUID_FOR_OBJECT>')
...使用以下格式从数据库中获取所需的对象...
{
"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"
}
当我尝试将pluck
orgetField
函数添加到查询以隔离和检索'prescriptions'
数组时,问题就出现了。这是我的控制器中用于呼叫的功能...
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 })
})
}
当我调用 API 路径访问此数据并执行all
函数时,我得到以下响应...
{
status: 200,
data: []
}
但是,完全相同的查询在Rethink
管理控制台的数据浏览器中按预期工作。
非常感谢任何关于为什么会发生这种情况的想法或帮助!