I am trying to improve the performance of a mongo query(a page long) that uses various pipeline stages and transforms the data into various formats.
SAMPLE DATA
https://jsoneditoronline.org/?id=d2075cafc09e4c1eb71d323b81fb474f
QUERY
https://jsoneditoronline.org/?id=6ecf6baac4a247d6952096aa1cc019b3
EXECUTION STATS WITH INDEX ON MULTIPLE FIELD
https://jsoneditoronline.org/?id=a1dd2e4286c14c3e886e120f59a993d5
The execution time of a single query is very less < 2 secs but on doing a load test with the following configuration
Total Number of records = 20,000 Concurrency - 50 (30 minutes) M30 instance with 3 replica sets The index was set on all match and sort fields No other process/queries were running when the load test was done.
There is also a version of this query that uses facet with group. On running these query via a flask server the db.profile stats says the query execution took somewhere around 17-30 seconds.
Is this the expected behavior of mongodb when it comes to complex queries.