Back

[SOLVED] Inconsistency between online Doc and Examples in libs?

  • 0
  • Web
Gildas Quiniou
10 Jun, 2023, 14:21

Hi, I'm fighting with writing functions and I discovered some inconsistency in the docs. The doc say const promise = databases.createDocument('[DATABASE_ID]', '[COLLECTION_ID]', '[DOCUMENT_ID]', {}); but looking at the node-appwrite lib I found async createDocument(collectionId, documentId, data, read, write). It's missing the [DATABASE_ID] part? Is the online doc up-to-date? BTW, none of the 2 work for me at the moment, but am I missing something? Anywhere with some sample with functions creating docs? Thx.

TL;DR
The user found a solution to their problem of inconsistency between the online documentation and the examples in the libraries. They resolved their issue with the network part on macOS Docker by using the `host.docker.internal` public IP. They also found a bug in the deployment process. The user discovered that their `package.json` was incorrect and may have been an old code example. They also mentioned using a different command to build the function package. They encountered an issue with an old version of a package, `node-appwrite`, and found that their `package-lock` showed a newer version. The user clarified where they were seeing an example without the database
joeyouss
10 Jun, 2023, 14:25

Hi lemme quiickly take a look

joeyouss
10 Jun, 2023, 14:29

also which page did you read this?

joeyouss
10 Jun, 2023, 14:41

also, to learn about why is it not working for you - any errors you got?

Gildas Quiniou
10 Jun, 2023, 16:19

Well, the doc is here : https://appwrite.io/docs/server/databases?sdk=nodejs-default#databasesCreateDocument The code is node-appwrite/lib/services/database.js ~line #800. Also the examples in node-appwrite/docs/examples/database/create-document.md (line 14). Regarding my code I just found that my endpoint is not suitable for localhost environment but strangely I didn't have any error until now... Gonna investigate. BTW, the doc suggest using the host IP but I'm not confident with that, as by default a container should not be able to connect to host. Also, I'm on macOS, that could be a reason for the host IP to be unreachable. Should I use some other IP from a network build up by Docker?

Gildas Quiniou
10 Jun, 2023, 16:31

Could I use http://appwrite-executor/v1 as endpoint?

Drake
10 Jun, 2023, 16:32

Can you clarify where you're seeing the example without the database id? Im looking at https://github.com/appwrite/sdk-for-node/blob/68e46fd078183c05d36c31caa2a3979076ae4f83/docs/examples/databases/create-document.md?plain=1#L14 and I see database id.

A container can connect to the host if the host is listening on the port

Drake
10 Jun, 2023, 16:33

No, that's not the right service

Gildas Quiniou
10 Jun, 2023, 16:35

I did a npm i node-appwrite to embed it with my function and found that code in the node_module/node-appwrite then.

Drake
10 Jun, 2023, 16:38

What's the package.json in there say for the version? Or maybe you can look in your package lock

Gildas Quiniou
10 Jun, 2023, 16:41

Sure. From package-lock :

TypeScript
   "packages": {
      "": {
         ...
         "dependencies": {
            ...
            "node-appwrite": "^5.0.0"
         }
      },

then

TypeScript
...
      "node_modules/node-appwrite": {
         "version": "5.1.0",
         "resolved": "https://registry.npmjs.org/node-appwrite/-/node-appwrite-5.1.0.tgz",
         "integrity": "sha512-CuSa4z7mh0VgR+VkjKWVuwpwiDU2pHNkSFpSEEo/gYJXgPpaNWguJfdJJKFTbUgC1CfIRUHYBLQIdHTX/LgsIg==",
         "dependencies": {
            "axios": "^0.26.1",
            "form-data": "^4.0.0"
         }
      },
Gildas Quiniou
10 Jun, 2023, 16:44

Hmm... npmjs.org shows V 9.0.0. Why did I got such old version?

Gildas Quiniou
10 Jun, 2023, 16:46

BTW, I also use docker run --rm --interactive --tty --volume $PWD:/usr/code openruntimes/node:v2-18.0 sh /usr/local/src/build.sh to build the function package. It should be more up-to-date, no?

Gildas Quiniou
10 Jun, 2023, 16:51

OK, got it, my package.json was wrong. I may have picked an old code example. The package is in sync with the doc. Remain my prob with the endpoint...

Drake
10 Jun, 2023, 17:12

Easiest thing to do is to use your LAN IP if you're running locally

Gildas Quiniou
10 Jun, 2023, 17:21

Unfortunately on macOS Docker is running in a VM. They did a good just to make it work as close as it does on a native Linux machine but the network part is a piece of tweaks. Hopefully I just got it to work, the public IP can be replaced by host.docker.internal which bridges to the localhost IP stack and all seem to work as expected now! Thanks for your help. BTW, I found a bug in the way the Deployment works, even if I leave the Activate deployment after build unchecked (Manual option), the deployment is done anyway.

Drake
10 Jun, 2023, 21:18

[SOLVED] Inconsistency between online Doc and Examples in libs?

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more