【发布时间】:2019-02-11 03:31:43
【问题描述】:
我正在尝试通过主键获取 RethinkDB 中的数据。但是,我的代码找不到数据。
我正在使用 RethinkDBDash 驱动程序来获取数据等,我将 Rethink 定义为 client.db。 ID 是我从 API 获取的数据的切片数组,当我在控制台记录它时,该值是 1。我通过简单地输入整数 1 来测试它并且它能够获取数据,但是,当我使用 API 中的数据抓取它,它返回一个空错误。我试图获取数据的表名为建议,主键为 sid,最初为 id。表格如下所示:
{
"author": {
"id": "535986058991501323"
} ,
"sid": 1 ,
"status": "PENDING" ,
"suggestion": "wtf"
}
在过去的项目中,我已经能够使用这种精确的方法从主键中获取数据没有问题。
const id = args.slice(0).join(' ');
console.log(id);
const data = await client.db.table('suggestions').get(id).run();
console.log(data.sid);
通过抓取数据,我期望控制台日志的值为 1。但是,我得到的是这样的错误:
(node:34984) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'sid' of null
at Object.run (C:\Users\facto\Desktop\Projects\JavaScript\Bots\CountSill\commands\deny.js:7:26)
(node:34984) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:34984) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
【问题讨论】:
标签: rethinkdb rethinkdb-javascript rethinkdbdash