Back

[Solved] Cannot Create Document

  • 0
  • Functions
KingBob
2 Dec, 2023, 20:20

Hello! I have tried to create a document but I keep getting the following error in my nodejs function

"UserEmailHere (role: users) missing scope (databases.read)"

I still get this error after creating the database and collection and setting permissions for the collection to "All Users". I also used the .setJWT(jwtToken). The collection ID is "1"

Here is my code: const db = await database.createDocument("databaseIDHere",'1',ID.unique(),{ 'clockIn':Date.now(), 'clockOut':Date.now()+new Date(2023,12,2,15), 'userId':user.$id }) return res.json(JSON.stringify({ db }))

Thanks in advance

TL;DR
I received an error while trying to create a document in my Node.js function. The error states that the user is missing the scope "databases.read" even though I have created the database, collection, and set permissions. The collection ID is "1". Can someone please help? Solution: The issue was with the Date code. It should be corrected to "new Date(Date.now())" instead of just "Date.now()".
KingBob
2 Dec, 2023, 20:44

The solution is new Date(Date.now()). Everything in appwrite was correct. I just got the Date code messed up. I set the type on the collection to be a Date type. Date.now() returns a number

KingBob
2 Dec, 2023, 20:46

[Solved] Cannot Create Document

Drake
2 Dec, 2023, 21:23

The key thing is to send a iso formatted string. I guess JavaScript converts date objects to that automatically

KingBob
2 Dec, 2023, 21:39

Thank you

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