Back

Increase integer without fetching doc

  • 1
  • Databases
Brave
4 May, 2023, 17:53

Completly possible in mysql πŸ˜„

TL;DR
The user wants to increase an integer value without fetching the document. Other users suggest using the `updateDocument()` function in the Appwrite Server SDK to update the value. However, it is uncertain if this solution will work and the user is asked to test it. The possibility of performing this task in MySQL is mentioned.
Brave
4 May, 2023, 17:53
safwan
4 May, 2023, 17:53

as far as i know, you will have to fetch the document in order to read the values in it. There's no way for your app to know what to update in your document without fetching it first.

safwan
4 May, 2023, 17:54

Ah yes it works in vanilla SQL, but I don't think appwrite has that functionality yet. Let me check just to be sure

safwan
4 May, 2023, 17:57

Okay so this might do what you want. Not a 100% sure as I haven't tested it myself.

Update Document in the Server SDK: https://appwrite.io/docs/server/databases?sdk=nodejs-default#databasesUpdateDocument

According to the docs, you can pass something in the data param.

safwan
4 May, 2023, 17:58
TypeScript
const promise = databases.updateDocument('[DATABASE_ID]', '[COLLECTION_ID]', '[DOCUMENT_ID]', {'logins': 'logins+1'});

Maybe something like this?

safwan
4 May, 2023, 17:58

Please test and let me know if it works!

Brave
4 May, 2023, 17:59

I have a function right here πŸ˜„

Brave
4 May, 2023, 17:59

I can test it

Brave
4 May, 2023, 18:02

{"code":400,"type":"document_invalid_structure","response":{"message":"Invalid document structure: Attribute \"CurrentStation\" has invalid format. Value must be a valid range between 1 and 99","code":400,"type":"document_invalid_structure","version":"1"}}

safwan
4 May, 2023, 18:05

Can you share your code snippet?

safwan
4 May, 2023, 18:05

I think I know what the issue is, just want to be sure.

Brave
4 May, 2023, 18:05

Pretty funny btw if you do this

Brave
4 May, 2023, 18:06

it just turns the value to 69

Brave
4 May, 2023, 18:06

ignoring the +

Brave
4 May, 2023, 18:06
safwan
4 May, 2023, 18:07

Ah yes. In the example I provided pseudo-code. 'CurrentStation+1' needs to hold some sort of operation

safwan
4 May, 2023, 18:08

The CurrentStation attribute in your collection is of type integer right? Well in this code you're passing a string. Which is why you're getting the above error.

safwan
4 May, 2023, 18:10

Now that I think about it, it might not be possible to directly update it

Brave
4 May, 2023, 18:11

<a:rollsad:826037118953586699>

Brave
4 May, 2023, 18:12

@Steven You are good in this stuff πŸ˜„ Do you have an idea?

Drake
4 May, 2023, 18:14

not possible 😜

Drake
4 May, 2023, 18:14

here's the related feature request: https://github.com/appwrite/appwrite/issues/3905

Brave
4 May, 2023, 18:15

Oh ok I didnt find it

Brave
4 May, 2023, 18:15
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