[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
- How connect an existing sveltekit projec...
The docs are splitte with two different versions... ### [Oficial Docs](https://appwrite.io/docs/quick-starts/sveltekit): **1. Create project** **2. Create Sve...
- Can't activate appwrite education
Hi, I'm a student and I have activated my GitHub Education benefits but I already had an AppWrite account. I tried to log out and log back in from the education...
- Type 'Theme' does not satisfy the constr...
Type 'Theme' does not satisfy the constraint 'Row'. Type 'Theme' is missing the following properties from type 'Row': $id, $sequence, $tableId, $databaseId, a...