How do you get access to the master node in Mongoid > 3.0 ?
In Mongoid < 3.0 you could use:
Mongoid::Config.master.eval('...')
The closest I can find in 3 seems to be:
klass.collection.database.command(eval: '...') #=> failed with error "not master"
Is there a better way to get access to master? Or a way to ensure the command is evaluated by the master node?
Mongoid 3.0 uses Moped and not the 10gen driver, so see Moped::Cluster#with_primary
http://rubydoc.info/github/mongoid/moped/master/Moped/Cluster:with_primary
For example:
output:
Note that other possible solutions like group, aggregation, and mapreduce are recommended over eval.