Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-2248

Faster exists? method

    • Type: Icon: Task Task
    • Resolution: Done
    • 12_01_17
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      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.

            Assignee:
            Unassigned Unassigned
            Reporter:
            jonhyman Jon Hyman
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: