api-platform / api-platform/core

[MongoDB] Use QueryBuilder when no lookup needed

Open
#7,995 6 comments 2 reactions 0 assignees View on GitHub
doctrine MongoDB performance
Dominant language
PHP
Stars
2.6k
Forks
980
Avg merge
2d 5h
Merged PRs (30d)
48

Description

Hello, I'm testing mongodb odm support using **doctrine/mongodb-odm-bundle:4.0.0** and **api-platform/api-platform:2.5.0**

I'm experencing very poor performance with large datasets (2 million documents aprox.).
I suppose, it may be caused becase of use of Doctrine AggregationBuilder, for filtering and pagination.

I created a custom PaginationExtension using Doctrine Query/Builder instead with skip() and limit() methods and performance is 50x faster for the same dataset (partial pagination for now).

I tested command launched by Api Platform in mongo shell too::

`time mongo --eval 'db.users.aggregate([{"$sort":{"_id":1}},{"$facet":{"results":[{"$skip":0},{"$limit":30}],"count":[{"$count":"count"}]}}])' api-mongodb`
```
real 0m4.547s
user 0m0.061s
sys 0m0.026s
```
time mongo --eval 'db.users.find().skip(0).limit(30)' api-mongodb; mongo --eval 'db.users.count()';
```
eal 0m0.083s
user 0m0.057s
sys 0m0.007s
```
Is this something already detected? If the answer is yes...
Is there any plan at future releases to improve MongoDB integration performance avoiding use aggregates for Filters and Extensions?

Thanks in advance...

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.