i am building a social media app and i am a beginner for databases and only discovered recently the populate-functionality and like it a lot especially in combination with the ref-functionality in Schemas.
For Example: When someone write a text and it contains also pictures, i only want to put the reference of the image-documents(the image is hosted on a S3 Buckets and the documents only contain the links, metadata, etc.) in the text-document.
So TextSchema like:
Now when someone wants to get the text, i only populate the references and get the url from the images and put it into the response of the server to the frontend. So you have the textbody and the imagelinks with one request.
I like this approach a lot, because i have a clear structure, dont save the same data in two differenct places, when i change the image-document, it will automatically update the data in the text-document, etc.
AND performance wise: i only request the database once (is this even true?).
The other approaches would be:
2. Put the data directly into the textdocument (so dont use ref and dont use populate). But then i would have the same data in to different places.
So now my beginner-question is:
Can i use this a lot (ref the comments of a text in the TextSchema and populate it, ref the texts of the user in the UserSchema and populate it, etc.).
Or is it under the hood not so simple (possibly even doing more than one request)? Has to do the server a lot of work and processing ?
I could not find a satisfactory answer to this question with google
Thanks a lot for the help. If someone has good resources for this topic (Text or Video), it would also be nice.