Askar
Askar

Reputation: 5854

error related to ruby 1.9.3 and mongodb driver

I have installed following the tutorial

$gem install mongo
Successfully installed mongo-1.8.6
1 gem installed
Installing ri documentation for mongo-1.8.6...
Installing RDoc documentation for mongo-1.8.6...

and

gem install bson_ext
Building native extensions.  This could take a while...
Successfully installed bson_ext-1.8.6
1 gem installed
Installing ri documentation for bson_ext-1.8.6...
Installing RDoc documentation for bson_ext-1.8.6...

My mongo.rb

#!/usr/bin/ruby -w

require 'mongo'
include Mongo

mongo_client = MongoClient.new("localhost", 27017)
db = mongo_client.db("somedb")
coll = db.collection("somecoll")

When I ran mongo.rb, I got the error:

/home/askar/.rvm/gems/ruby-1.9.3-p429/gems/bson_ext-1.8.6/ext/bson_ext/bson_ext/cbson.so: warning: method redefined; discarding old legal?
/home/askar/.rvm/gems/ruby-1.9.3-p429/gems/bson-1.8.6/lib/bson/types/object_id.rb:39: warning: previous definition of legal? was here
/home/askar/.rvm/gems/ruby-1.9.3-p429/gems/bson_ext-1.8.6/ext/bson_ext/bson_ext/cbson.so: warning: method redefined; discarding old from_string
/home/askar/.rvm/gems/ruby-1.9.3-p429/gems/bson-1.8.6/lib/bson/types/object_id.rb:107: warning: previous definition of from_string was here
/home/askar/.rvm/gems/ruby-1.9.3-p429/gems/bson_ext-1.8.6/ext/bson_ext/bson_ext/cbson.so: warning: method redefined; discarding old to_s
/home/askar/.rvm/gems/ruby-1.9.3-p429/gems/bson-1.8.6/lib/bson/types/object_id.rb:119: warning: previous definition of to_s was here
/home/askar/.rvm/gems/ruby-1.9.3-p429/gems/mongo-1.8.6/lib/mongo/util/pool_manager.rb:267: warning: mismatched indentations at 'end' with 'def' at 259
/home/askar/.rvm/gems/ruby-1.9.3-p429/gems/mongo-1.8.6/lib/mongo/db.rb:339: warning: assigned but unused variable - e
/home/askar/.rvm/gems/ruby-1.9.3-p429/gems/mongo-1.8.6/lib/mongo/gridfs/grid.rb:24: warning: assigned but unused variable - connection
/home/askar/.rvm/gems/ruby-1.9.3-p429/gems/mongo-1.8.6/lib/mongo/gridfs/grid_file_system.rb:25: warning: assigned but unused variable - connection
/home/askar/.rvm/gems/ruby-1.9.3-p429/gems/mongo-1.8.6/lib/mongo/util/write_concern.rb:32: warning: instance variable @legacy_write_concern not initialized
/home/askar/.rvm/gems/ruby-1.9.3-p429/gems/mongo-1.8.6/lib/mongo/util/write_concern.rb:32: warning: instance variable @legacy_write_concern not initialized
/home/askar/.rvm/gems/ruby-1.9.3-p429/gems/mongo-1.8.6/lib/mongo/util/write_concern.rb:32: warning: instance variable @legacy_write_concern not initialized
/home/askar/.rvm/gems/ruby-1.9.3-p429/gems/mongo-1.8.6/lib/mongo/util/logging.rb:41: warning: instance variable @instrumenter not initialized
/home/askar/.rvm/gems/ruby-1.9.3-p429/gems/mongo-1.8.6/lib/mongo/mongo_client.rb:523: warning: instance variable @max_message_size not initialized
/home/askar/.rvm/gems/ruby-1.9.3-p429/gems/mongo-1.8.6/lib/mongo/mongo_client.rb:519: warning: instance variable @max_bson_size not initialized
/home/askar/.rvm/gems/ruby-1.9.3-p429/gems/mongo-1.8.6/lib/mongo/mongo_client.rb:519: warning: instance variable @max_bson_size not initialized
/home/askar/.rvm/gems/ruby-1.9.3-p429/gems/mongo-1.8.6/lib/mongo/util/write_concern.rb:32: warning: instance variable @legacy_write_concern not initialized
/home/askar/.rvm/gems/ruby-1.9.3-p429/gems/mongo-1.8.6/lib/mongo/util/write_concern.rb:32: warning: instance variable @legacy_write_concern not initialized

But, in irb it seems ok:

$irb
1.9.3-p429 :001 > require 'mongo'
 => true 
1.9.3-p429 :002 > include Mongo
 => Object 
1.9.3-p429 :003 > mongo_client = MongoClient.new("localhost", 27017)
 => #<Mongo::MongoClient:0x00000001b5d618 @host="localhost", @port=27017, @id_lock=#<Mutex:0x00000001b5d550>, @primary=["localhost", 27017], @primary_pool=#<Mongo::Pool:0xdb22d4 @host=localhost @port=27017 @ping_time= 0/1 sockets available up=true>, @mongos=false, @tag_sets=[], @acceptable_latency=15, @slave_ok=nil, @ssl=nil, @unix=false, @socket_class=Mongo::TCPSocket, @auths=[], @pool_size=1, @pool_timeout=5.0, @op_timeout=nil, @connect_timeout=30, @logger=nil, @read=:primary, @write_concern={:w=>1, :j=>false, :fsync=>false, :wtimeout=>nil}, @read_primary=true, @max_bson_size=16777216, @max_message_size=48000000> 
1.9.3-p429 :004 > db = mongo_client.db("somedb")
 => #<Mongo::DB:0x00000001b66e48 @name="somedb", @connection=#<Mongo::MongoClient:0x00000001b5d618 @host="localhost", @port=27017, @id_lock=#<Mutex:0x00000001b5d550>, @primary=["localhost", 27017], @primary_pool=#<Mongo::Pool:0xdb22d4 @host=localhost @port=27017 @ping_time= 0/1 sockets available up=true>, @mongos=false, @tag_sets=[], @acceptable_latency=15, @slave_ok=nil, @ssl=nil, @unix=false, @socket_class=Mongo::TCPSocket, @auths=[], @pool_size=1, @pool_timeout=5.0, @op_timeout=nil, @connect_timeout=30, @logger=nil, @read=:primary, @write_concern={:w=>1, :j=>false, :fsync=>false, :wtimeout=>nil}, @read_primary=true, @max_bson_size=16777216, @max_message_size=48000000>, @strict=nil, @pk_factory=nil, @write_concern={:w=>1, :j=>false, :fsync=>false, :wtimeout=>nil}, @read=:primary, @tag_sets=[], @acceptable_latency=15, @cache_time=300> 
1.9.3-p429 :005 > coll = db.collection("somecoll")
 => #<Mongo::Collection:0x00000001ba9518 @name="somecoll", @db=#<Mongo::DB:0x00000001b66e48 @name="somedb", @connection=#<Mongo::MongoClient:0x00000001b5d618 @host="localhost", @port=27017, @id_lock=#<Mutex:0x00000001b5d550>, @primary=["localhost", 27017], @primary_pool=#<Mongo::Pool:0xdb22d4 @host=localhost @port=27017 @ping_time= 0/1 sockets available up=true>, @mongos=false, @tag_sets=[], @acceptable_latency=15, @slave_ok=nil, @ssl=nil, @unix=false, @socket_class=Mongo::TCPSocket, @auths=[], @pool_size=1, @pool_timeout=5.0, @op_timeout=nil, @connect_timeout=30, @logger=nil, @read=:primary, @write_concern={:w=>1, :j=>false, :fsync=>false, :wtimeout=>nil}, @read_primary=true, @max_bson_size=16777216, @max_message_size=48000000>, @strict=nil, @pk_factory=nil, @write_concern={:w=>1, :j=>false, :fsync=>false, :wtimeout=>nil}, @read=:primary, @tag_sets=[], @acceptable_latency=15, @cache_time=300>, @connection=#<Mongo::MongoClient:0x00000001b5d618 @host="localhost", @port=27017, @id_lock=#<Mutex:0x00000001b5d550>, @primary=["localhost", 27017], @primary_pool=#<Mongo::Pool:0xdb22d4 @host=localhost @port=27017 @ping_time= 0/1 sockets available up=true>, @mongos=false, @tag_sets=[], @acceptable_latency=15, @slave_ok=nil, @ssl=nil, @unix=false, @socket_class=Mongo::TCPSocket, @auths=[], @pool_size=1, @pool_timeout=5.0, @op_timeout=nil, @connect_timeout=30, @logger=nil, @read=:primary, @write_concern={:w=>1, :j=>false, :fsync=>false, :wtimeout=>nil}, @read_primary=true, @max_bson_size=16777216, @max_message_size=48000000>, @logger=nil, @cache_time=300, @cache={}, @write_concern={:w=>1, :j=>false, :fsync=>false, :wtimeout=>nil}, @read=:primary, @capped=nil, @tag_sets=[], @acceptable_latency=15, @pk_factory=BSON::ObjectId, @hint=nil> 
1.9.3-p429 :006 > 

Actually when I run mongo.rb it should not showing anything because I'm just specifying what db and collection to use.

MongoDB version is 2.4.3.

Sorry that subject is not specific.

Upvotes: 0

Views: 464

Answers (1)

toro2k
toro2k

Reputation: 19238

Those are not errors, they are warnings:

/home/askar/.rvm/gems/ruby-1.9.3-p429/gems/bson_ext-1.8.6/ext/bson_ext/bson_ext/cbson.so: warning: method redefined; discarding old legal?

They do not prevent you from executing the program, they just inform you about potential problems in the code: uninitialized instance variables, overridden methods and the like.

They show up because you are calling ruby with the -w option. You can use the same options with irb:

$ irb -w
irb> require 'mongodb'
/home/toro2k/.gem/ruby/1.9.1/gems/bson_ext-1.8.6/ext/bson_ext/bson_ext/cbson.so: warning: method redefined; discarding old legal?
...
...

Upvotes: 2

Related Questions