pluck vs distinct in mongoid db. which is faster?
问题 It seems that mongodb has two equivalent methods: #pluck and #distinct which both return only given fields from a collection. so both User.pluck(:name) User.distinct(:name) would return array of all names from User collection in db > ['john', 'maria', 'tony', 'filip'] I don't mind duplicates. Which method is faster? 回答1: Let's run a benchmark! require 'benchmark' 1_200.times { FactoryGirl.create(:user) } Benchmark.bmbm(7) do |bm| bm.report('pluck') do User.pluck(:email) end bm.report('pluck