Web Developer
Hi all,
I am trying to create a function which connects to my db but I am getting a database not found error. I have put the exact db & collection IDs but still there is error. I have tried sending a simple text response & that worked, means path and everything is set correctly. I have also given correct permissions in db and collections. I have also selected All in the Scopes of my Function. But when I am trying to do a listDocuments call to my db, it is saying db not found.
I have used this tutorial for this
https://www.youtube.com/watch?v=PmEIu-qrcac&list=PL-nc7zI7zjsbGzYBiG_V3tEFpmlzzbJgC&index=4
Here is my code. I tried replacing the IDs of the project, db and collections with the exact id, but still it is an issue. The star mark is where I put my IDs.
import { Client, Databases } from "node-appwrite";
export default async ({ req, res, log, error }) => {
const client = new Client()
client
.setEndpoint('https://cloud.appwrite.io/v1')
.setProject('project id here ***')
const db = new Databases(client)
if (req.method == 'GET') {
const response = await db.listDocuments(
'db id here ***',
'collcetions id here ***'
)
return res.json(response.documents)
}
return res.send("Shlok, tesing if user delete worked")
}
Below is my error -
Error: Database not found
at Client.call (/usr/local/server/src/function/node_modules/node-appwrite/lib/client.js:168:31)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Databases.listDocuments (/usr/local/server/src/function/node_modules/node-appwrite/lib/services/databases.js:905:16)
at async Module.default (file:///usr/local/server/src/function/functions/main.js:12:26)
at async execute (/usr/local/server/src/server.js:208:16)
at async action (/usr/local/server/src/server.js:225:7)
at async /usr/local/server/src/server.js:14:5