I'm trying to get the list of documents with the Appwrite function, unfortunately, I can't get any value.
const sdk = require("node-appwrite"); module.exports = async function (req, res) { const client = new sdk.Client(); // You can remove services you don't use const database = new sdk.Databases(client); if ( !req.variables["APPWRITE_FUNCTION_ENDPOINT"] || !req.variables["APPWRITE_FUNCTION_API_KEY"] ) { console.warn( "Environment variables are not set. Function cannot use Appwrite SDK." ); } else { client .setEndpoint(req.variables["APPWRITE_FUNCTION_ENDPOINT"]) .setProject(req.variables["APPWRITE_FUNCTION_PROJECT_ID"]) .setKey(req.variables["APPWRITE_FUNCTION_API_KEY"]) .setSelfSigned(true); } const DbCollection = "64bb1ee4200b221e0675"; const usersCollection = "64bb1f396ed41ad9c1d8"; const prayerPartnerCollection = "6545e03a11aa6b5ba77a"; const prayerPartnerHistoryCollection = "6545e4ba5bcad02198c0"; const notificationCollection = "654cd8010d7f67c0d238"; const promise = database.listDocuments(DbCollection, usersCollection); promise.then( function (response) { res.json({ myResponse: response, }); }, (error) { console.log(error); res.json({ myError: error, endPoint: req.variables["APPWRITE_FUNCTION_ENDPOINT"], projectId: req.variables["APPWRITE_FUNCTION_PROJECT_ID"], functionApi: req.variables["APPWRITE_FUNCTION_API_KEY"], }); } ); };
over the past 7hrs, I have been reading appwrite documentation on how to make this code work, but nothing I do seems to work, i have to try PHP runtime yet, nothing its working.
please what am I doing wrong?
@Drake good day Sir,
Sir please can you make me understand what I'm doing Wrong on this code?
is this a cloud ? or self hosted?
Please don't tag people as it can be very disruptive. You can post and wait for anyone to respond.
FYI, it's best to wrap code in backticks to format a bit nicer. You can use 1 backtick for inline code (https://www.markdownguide.org/basic-syntax/#code) and 3 backticks for multiline code (https://www.markdownguide.org/extended-syntax/#syntax-highlighting.
It's really hard to read the code, but the problem could be that the function is returning before the promise is resolved. I recommend not using promise.then. Instead, use async await.
Pls take a look at it here
Hello @Drake @Core @Mosh Ontong
I'm very aware everyone is on a busy schedule, can you please quickly take a look at what I'm doing wrong.
Thank you very much
@Zionnite let's not tag Core here please, especially since there are folks interacting in the thread
Steven has already responded on the StackOverflow question. Have you had a chance to review his answer and try the solution?
Recommended threads
- After assigning a domain to my Dart func...
I’ve attached the images. Could anyone please explain how this execution is being performed?
- I can't UNPAUSE my project with the free...
I received an email notifying me that my project had been paused due to inactivity, and the email included a link to "Restore project." However, that button red...
- How to bypass the rate limit on the back...
Once a month my app has a ton of usage and I always run into the Too many requests 429 error. I am trying to optimize the queues and jobs to manage that, but a...