I've a project based on a mongodb database and I need to accomplish the following description in a very optimized way. My database has a Document with another embedded documents and I need to apply pagination in this embedded documents, eg:
{ _id: "str", .... , emebedded_doc_example = [ {},{},{} ] }
The problem is that at first we didn't expect that embedded_doc_example
will grow as much as it is. So I want to apply pagination and filtering on server side on the embedded_doc_example
. Then I'm seeing two solutions:
1.Get all the embedded documents of a give parent's _id
and then apply the filters and the pagination in the list.
2.Separate the emebedded_docs_example
in another doc and create a relation to the old parent.
The problem is better for me since it doesn't requires a lot of refactoring. However, I don't know if this will improve the results a lot since I'm loading all the embedded objects of a given parent in memory. Am I right?