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
- I'm getting an error on the console "j?....
On my self hosted instance version 1.8.1 the console is giving me this error when trying to view the rows for a table I recently created. My application is read...
- Websites hosted on my appwrite sites hav...
Hello, all my websites hosted on appwrite sites are not running I am getting this message "This site can’t be reached drivehub.appwrite.network took too long t...
- Function global variables
when i create a top-level global variable in go or bun how will it behave? is the heap getting renewed on every execution or could i do some kind of temp. cachi...