我正在尝试通过主键获取RethinkDB中的数据。但是,我的代码找不到数据。
我使用RethinkDBDash驱动程序来获取数据,我将Rethink定义为client.db。ID是我从API获取的数据的切片数组,当我在控制台记录它时,值是1。我通过简单地输入整数1进行了测试,它能够获取数据,但是,当我使用API中的数据获取数据时,它返回一个空错误。我试图在其上获取数据的表名为suggestions,主键为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.发布于 2019-02-12 06:50:11
我发现了这个问题,主键需要一个整数而不是字符串,所以它查找整数而不是字符串,由于找不到它,它抛出了一个错误。要解决这个问题,我只需将数据从整数更改为字符串。您也可以只使用parseInt函数将数组从字符串转换为整数。
https://stackoverflow.com/questions/54623610
复制相似问题