I'm attempting to grab data in RethinkDB by the primary key. However, my code cannot find the data.
I'm using the RethinkDBDash driver to grab the data and such, I defined Rethink as client.db. The ID is a sliced array from data I'm grabbing from an API, when I console log it, the value is 1. I tested this out by simply entering the integer 1 and it was able to grab the data, however, when I use the data from the API to grab it, it returns a null erorr. The table I am trying to grab data on is named suggestions with a primary key of sid, originally id. The table looks like this:
{
"author": {
"id": "535986058991501323"
} ,
"sid": 1 ,
"status": "PENDING" ,
"suggestion": "wtf"
}
On past projects, I have been able to grab data from the primarykey no problem using this exact method.
const id = args.slice(0).join(' ');
console.log(id);
const data = await client.db.table('suggestions').get(id).run();
console.log(data.sid);
From grabbing the data, I expected a console log with the value 1. However, what I got was an error that says this:
(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.
I figured out the issue, the primarykey expects an integer rather than a string, so it looks for an integer rather than a string and since it can't find it, it throws an erorr. To fix it, I just had to change the data from an integer to a string. You can also just use the parseInt function to convert the array from a string to an integer.