mongoid/mongoid — pull request #2248 by jonhyman (2012-07-26 13:20:30+00:00)
Title: Faster exists? method

Mongo does not use counted b-tree indexes: https://jira.mongodb.org/browse/SERVER-1752?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=147517#comment-147517

As such, `Model.where(...).count` can be very slow. When checking for the existence of some document set, there's no need to suffer through the slowness of count only to check > 0 (since, if one document is found, `exists?` should return true, no need to keep looking).

This pull request updates the `exists?` method to try to find a lone document instead of checking against the count.