I have hundreds of element to get from MongoDB database and print them in the front-end. Fetch all into single one request could decrease performance as it carries big payload in the body response. So I'm looking for a solution to split my Angular request into several and with the constraint to be simultaneous.
Example :
MONGODB Collection: Elements (_id, name, children, ...) Documents: 10000+
But we only need ~100-500 elements
ANGULAR :
const observables = [];
const iteration = 5, idParent = 'eufe4839ffcdsj489483'; // example
for (let i = 0; i < iteration; i++) {
observables.push(
this.myHttpService.customGetMethod<Element>(COLLECTION_NAME, endpoint, 'idParent=' + idParent + '&limit=??')); // url with query
}
forkJoin(observables).subscribe(
data => {
this.elements.push(data[0]);
this.elements.push(data[1]);
},
err => console.error(err)
);
I use forkJoin because I need simultaneous requests for better performance. The idea is to send multiple requests to the back-end with different limit parameter values and get the whole set of elements into the data object at the end. The only purpose is to split request to avoid big latency with maybe errors due to the size of the payload body.
How can I proceed with the given stack to perform such this operation ? I would like to avoid the use of websockets.