diff --git a/src/Query.php b/src/Query.php index f1a8c2386..5dc0c1acc 100644 --- a/src/Query.php +++ b/src/Query.php @@ -495,7 +495,24 @@ public function exists($db = null) if (!empty($this->emulateExecution)) { return false; } + + #better performance + #save last options + $tmpOrderBy = $this->orderBy; + $tmpLimit = $this->limit; + $tmpOffset = $this->offset; + $tmpSelect = $this->select; + $this->orderBy = []; + $this->limit = 1; + $this->offset = null; + $this->select = ['_id']; $cursor = $this->buildCursor($db); + #return last options + $this->orderBy = $tmpOrderBy; + $this->limit = $tmpLimit; + $this->offset = $tmpOffset; + $this->select = $tmpSelect; + foreach ($cursor as $row) { return true; }