Skip to content
Back

[CLOSED] How can I populate the database fields automatically like mongoose?

  • 0
  • Databases
  • General
joeyouss
31 Jul, 2023, 10:49

have you tried this once? https://appwrite.io/docs/client/databases?sdk=web-default#databasesGetDocument

I don't understand fully about your question but feel free to point me in a different direction

TL;DR
The user is asking for a way to automatically populate database fields like in mongoose. They mention creating a feature request and express concerns about payload size when adding new items. Other users mention limitations and improvements to be made in relationships. There is no solution provided in the thread.
Vishal Lohar
31 Jul, 2023, 12:35

Yes, I have tried the getDocument method. But let's say instead of settings I have a orders array with order ids as strings. I fetched the main document that contains all the order ids. Now to get the order details I will have to run getDocument inside a for loop for every order id. This is a lengthy way.

If I was using Mongoose with MongoDB then I can use the Mongoose populate method to do this without extra effort. You can get more details on the mongoose populate method here - https://www.geeksforgeeks.org/mongoose-populate-method/

TypeScript
  id: "48hfdf9py74p9rfw",
  name: "Vishal Lohar",
  orders: [ "uiosuf89476r945r",  "uiosuf876r945r",  "uosuf876r945r"]
}```
Guille
31 Jul, 2023, 13:20

What you are looking is relationships: https://appwrite.io/docs/databases-relationships

Be aware, this feature is currently in beta and do not support making queries for child documents

Vishal Lohar
31 Jul, 2023, 14:20

Yes, Any information on stable version of relationships?

Guille
31 Jul, 2023, 14:52

I haven't seen any information in the repository about relationships for the next version 1.4, so I think it may have improvements in 1.5, sadly I don't have any information about dates

Vishal Lohar
31 Jul, 2023, 16:43

OkayπŸ‘

joeyouss
1 Aug, 2023, 10:30

aha, now I get it after reading the blog.

joeyouss
1 Aug, 2023, 10:30

Relationships yes, but, are restricted to a max depth of three levels.

Vishal Lohar
1 Aug, 2023, 10:49

Yes, I tried and it needs a lot of improvements. Beta version is not suitable for my project.

Vishal Lohar
1 Aug, 2023, 11:06

@joeyouss I have a doubt! I will use your relationships doc example.

TypeScript
await databases.updateDocument(
    'marvel',
    'movies',
    'spiderman',
    {
        title: 'Spiderman',
        year: 2002,
        reviews: [
            'review4',
            'review5'
        ]
    }
);

If I want to add new reviews to the movie then how can I do it? In the code example, it will just remove the old reviews relationship and will add review4, and review5 relationship. In the end, I will just have 2 reviews. But what if I have to add 3 new reviews? Will I have to pass all the reviews in my request body?

Guille
1 Aug, 2023, 13:34

You have to pass all he reviews again, probably you have to make a new call to get the current document and then push the new element and update it

Vishal Lohar
1 Aug, 2023, 13:35

Don't you think if I have a thousand reviews then the payload size will be too big?

Vishal Lohar
1 Aug, 2023, 13:37

Appwrite should add a method that can be used to add new items in the relationship without passing all the previous items. Something like passing permission while creating document.

Guille
1 Aug, 2023, 13:38

I agree with you, and it should one method to remove an element too, there are a lot improvements to do in relationships

Vishal Lohar
1 Aug, 2023, 13:39

Yes, Right! This is the reason I am not using this feature.

Vishal Lohar
1 Aug, 2023, 13:39

I guess, I can create a feature request for this

Guille
1 Aug, 2023, 13:40

That would be good, I haven't seen a request for this

Vishal Lohar
1 Aug, 2023, 13:40

Okay, I will create one request for this feature

Vishal Lohar
1 Aug, 2023, 14:08

https://github.com/appwrite/appwrite/issues/5925 - Please let me know if my description is not clear. I can make some edits

Drake
1 Aug, 2023, 17:44
Vishal Lohar
2 Aug, 2023, 03:24

What do you want to close? Github Issue or this support post

Drake
2 Aug, 2023, 03:24

The GitHub issue you created

Drake
2 Aug, 2023, 03:25

And then you can πŸ‘ the GitHub issue I linked

Vishal Lohar
2 Aug, 2023, 03:25

Alright, You can link both issues if possible. And then close mine

joeyouss
7 Aug, 2023, 11:11

[CLOSED] How can I populate the database fields automatically like mongoose?

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