[CLOSED] How can I populate the database fields automatically like mongoose?
- 0
- Databases
- General

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

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/
id: "48hfdf9py74p9rfw",
name: "Vishal Lohar",
orders: [ "uiosuf89476r945r", "uiosuf876r945r", "uosuf876r945r"]
}```

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

Yes, Any information on stable version of relationships?

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

Okay👍

aha, now I get it after reading the blog.

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

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

@joeyouss I have a doubt! I will use your relationships doc example.
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?

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

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

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.

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

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

I guess, I can create a feature request for this

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

Okay, I will create one request for this feature

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

Can we close this in favor of https://github.com/appwrite/appwrite/issues/2531?

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

The GitHub issue you created

And then you can 👍 the GitHub issue I linked

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

[CLOSED] How can I populate the database fields automatically like mongoose?
Recommended threads
- Relationship null, even when relationshi...
Hi Everyone, im experiencing issues with set relation data. When im setting the document id from the related database most of them seem fine, except one table. ...
- REQUEST FAILED IN MIGRATION
I was trying to moved my archived project to a self-host database . Though the Project is "read only" but there's a message that I can view and migrate data to...
- Is it possible to getRow with all relati...
With the new Opt-In relationship loading, is it possible to query getRow to get all attributes and relationships and possibly even cascading relationships? I tr...
