Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MongoDB Query->Exists() has no good performance #290

Open
ziaratban opened this issue Dec 27, 2019 · 2 comments
Open

MongoDB Query->Exists() has no good performance #290

ziaratban opened this issue Dec 27, 2019 · 2 comments
Labels
status:ready for adoption Feel free to implement this issue. type:enhancement Enhancement

Comments

@ziaratban
Copy link
Contributor

hi.
method exists() in yii\mongodb\Query by default has not projection or limit in command. so MongoDB return all document and field in result.

User::Find()->Where(['_id' => oid('5de3320034af172d38e38102')])->Exists()
#yii2 output: find({"ns":"myDB.users","filter":{"_id":"MongoDB\\BSON\\ObjectId(5de3320034af172d38e38102)"}})

vs

User::Find()->Select(['_id'])->Limit(1)->Where(['_id' => oid('5de3320034af172d38e38102')])->Exists()
#yii2 output: find({"ns":"myDB.users","filter":{"_id":"MongoDB\\BSON\\ObjectId(5de3320034af172d38e38102)"},"limit":1,"projection":{"_id":true}})

please see Benchmarking findOne() vs. find()->limit(1)->count(true)

@samdark
Copy link
Member

samdark commented Dec 27, 2019

We can likely add LIMIT 1 to exists by default.

@samdark samdark added status:ready for adoption Feel free to implement this issue. type:enhancement Enhancement labels Dec 27, 2019
@samdark
Copy link
Member

samdark commented Dec 27, 2019

@ziaratban want to try making a pull request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:ready for adoption Feel free to implement this issue. type:enhancement Enhancement
Projects
None yet
Development

No branches or pull requests

2 participants