Hi there, I'm shehryar, I'm new to react native and appwrite as well, I'm following a tutorial, what's surprising is the listRows({databaseId, tableId, queries}) is returning an empty response like {rows :[], total :0} but on the other hand when i call getRow({databaseId, tableId, rowId}) it works and I get an expected response. I'm not following what I am doing wrong. i have all permissions checked as well.
🙏 Will appreciate the help.
First of all, can you please tell whether that tutorial is new or old? I mean does it mentions old Collection based schema?
Please check this
it's not collection rather tables I believe.
I've found something in your code which possibly could be a reason behind this
You're querying without even checking that if the user exists or not in the first place
So, try checking for the user first by updating your code like this -
- Change no. 1
useEffect(() => {
fetchHabit();
}, []);
- Change no. 2
const fetchHabit = async () => {
if (!user?.$id) return;
const response = await databases.listRows({
databaseId: DATABASE_ID,
tableId: "habits",
queries: [Query.equal("createdBy", user.$id)],
});
console.log(response);
};
Okay its working but shouldn't it just give an error if the user doesn't exist since I'm using try catch
Thats bad for security. You dont want anyone to know if a certain user exists or not.
Definitely but in a dev environment, shouldn't it be throwing an error
How could appwrite determine if its a dev build or a production. Plus when you are doing query, the db does not know what UserId means. It just says, hey there is no document by this query.
UserId is something I'm creating from the ID module, secondly if it's a security measure from appwrite I suppose I can wrap my head around it.
No I meant like You are querying by an atrribute. It did not throw an error, cause the oparation isself correct. You tried to fetch something, which may or may not exist. Like alone in Moon calling elon musk. Is the calling incorrect? No Is elon musk a wrong thing? No But no one responded cause there is no elon musk on the moon 😅 The process is correct, the placement is wrong
Thanks 👍
Recommended threads
- IMPORTANT! SOC-2 Request Failing
Issue requesting SOC-2. If tried other/private browser as well as filling in optional fields.
- Appwrite-injected variables are not avai...
I am using rust-1.83 as a runtime and try to access APPWRITE_FUNCTION_API_ENDPOINT or APPWRITE_FUNCTION_API_KEY during runtime. Both are not set during my execu...
- Can you suppress row $meta data?
When using listRows with a 'select' query to limit the response [for performance], I'm still getting extra columns (eg. `$id`, `$sequence`, `$createdAt`, `$upda...