Back

how to create key value type structures?

  • 0
  • Databases
kriihz77
30 Sep, 2023, 17:58

I would like to understand how to create an attribute in the database structure that allows me to store data of type key value, structure of type json, if possible I would like to learn how to do it.

TL;DR
The user wants to know how to create key-value type structures. The suggestion is to use a separate collection to store the key-value pairs, such as a 'ratings' collection with attributes for bookId and rating. This allows for easier querying of the data. One option is to use a relationship attribute for the user, or manually use a string for the userId. Use a json-type field if available.
Drake
30 Sep, 2023, 18:01

can you provide more details about your use case?

kriihz77
30 Sep, 2023, 18:05

I would like to have a rating of a series of books per user, for example something like this:

{ Userid: 1234567, DateStart: DD/MM/YYYY, qualification:{ book1 : 10, Book2: 3, Book3: 4, ....... Bookn : 10 } }

kriihz77
30 Sep, 2023, 18:06

For the example I would like to save the ratings of each book in that structure.

Drake
30 Sep, 2023, 18:07

The way this is typically done is to use a separate collection (say ratings) where that collection will have a bookId and rating attribute.

Drake
30 Sep, 2023, 18:08

You can either use a relationship attribute for the user or manually use a string for the userId

Drake
30 Sep, 2023, 18:08

Keep in mind, relationships are experimental at the moment

kriihz77
30 Sep, 2023, 18:11

Thank you, it would be maintaining the relationship model. of SQL databases, although it would be good to include a json-type field as in supabase

kriihz77
30 Sep, 2023, 18:11

Although it would be good to use a string field like json?

Drake
30 Sep, 2023, 18:21

Some people do that. I don't recommend it because you wouldn't be able to query that

kriihz77
30 Sep, 2023, 19:38

Thank you, steven

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