Skip to content

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

Open
@ziaratban

Description

@ziaratban

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions