mongo-ruby-driver/docs/examples/replica_set.rb

25 lines
514 B
Ruby
Raw Normal View History

2010-11-29 18:56:11 +00:00
# This code assumes a running replica set with at least one node at localhost:27017.
require 'mongo'
cons = []
10.times do
2012-02-22 18:47:10 +00:00
cons << Mongo::ReplSetConnection(['localhost:27017'], :read => :secondary)
end
ports = cons.map do |con|
con.read_pool.port
end
puts "These ten connections will read from the following ports:"
p ports
cons[rand(10)]['foo']['bar'].remove
100.times do |n|
cons[rand(10)]['foo']['bar'].insert({:a => n})
end
100.times do |n|
p cons[rand(10)]['foo']['bar'].find_one({:a => n})
end