Open
Description
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)