I am using rails 4.1.8
along with ruby 2.1.2p95
and mongo-2.0.4
gem on ubuntu machine to connect from some controller (X) in rails to mongo db v3.0.3
. I have tried both the combination of code given below as suggested by many people. But i am getting the similar error in both the case:
require 'mongo'
include Mongo
def mongocon
@db = Mongo::Connection.new("192.168.56.102", 27017).db("convoos")
#@db = MongoClient.new("192.168.56.102", 27017).db("convoos")
end
Error :
uninitialized constant Mongo::Connection
uninitialized constant WorkdbController::MongoClient
You are using the new Mongo 2.0 driver which breaks backwards compatibility with the 1.x series. The code you are trying is for the 1.x series.
You simply need to do
require 'mongo'
db = Mongo::Client.new([ '192.168.56.102:27017' ], :database => 'convoos')
Here is the tutorial for the 2.x version of the Ruby Mongo Driver.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With