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

first without default sort by _id

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.1.3
    • Affects Version/s: None
    • Component/s: None
    • None

      We were profiling our log files today and I noticed we have a lot of limit 1, sorted by _id

      I think this is because we started using code similar to:

      u = User.where(email: '...').first

      When we really just wanted to say "we're not sure if the user exists with that email, so don't raise a not found error". This is also why we don't use find_by, because it's important for us to have raise_not_found_error left at the default value of true, so we can use that where it's needed. We have a unique index on email, so it's not like the sort is doing crazy tons of extra work, but I believe it is causing Mongo to use a different index than the default one (the index on email).

      Not a huge deal, but I was just curious if profiling had ever been done to see if those extra _id sorts where causing any extra work, or if there was a better way to accomplish what we were after. Thanks!

            Assignee:
            Unassigned Unassigned
            Reporter:
            barmstrong Brian Armstrong
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: