Skip to content

Instantly share code, notes, and snippets.

@yankov
Created November 8, 2011 22:18
Show Gist options
  • Save yankov/1349464 to your computer and use it in GitHub Desktop.
Save yankov/1349464 to your computer and use it in GitHub Desktop.
def where *params
shard_key = params.find{|x| x.has_key?(:player_id)}
params.first.merge!(:shard_id => Digest::MD5.hexdigest(shard_key[:player_id])) unless shard_key.nil?
super *params
end
# checking in console
ruby-1.9.2-p290 :079 > Activity.where(:player_id => "4e5d4e27b262e3fbe0000050").selector
=> {:deleted_at=>{"$exists"=>false}, :player_id=>BSON::ObjectId('4e5d4e27b262e3fbe0000050'), :shard_id=>"0ce2aee649f332e56751b41bc9e2844e"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment