简体   繁体   中英

NameError: uninitialized constant MongoClient

I'm using Ruby 2.2. I have installed mongo gem, but still get the error:

MY-MAC:ruby-2.2.0 me$ gem list

*** LOCAL GEMS ***

bigdecimal (1.2.6)
bson (4.0.3)
bundler (1.10.6)
bundler-unload (1.0.2)
executable-hooks (1.3.2)
gem-wrappers (1.2.7)
io-console (0.4.3)
json (1.8.1)
log4r (1.1.10)
mini_portile2 (2.0.0)
minitest (5.4.3)
mongo (2.2.3)
nokogiri (1.6.7.2)
power_assert (0.2.2)
psych (2.0.8)
rake (10.4.2)
rdoc (4.2.0)
rubygems-bundler (1.4.4)
rvm (1.11.3.9)
test-unit (3.0.8)
MY-MAC:ruby-2.2.0 me$ irb
2.2.0 :001 > require 'mongo'
 => true
2.2.0 :002 > include Mongo
 => Object
2.2.0 :003 > Mongo::VERSION
 => "2.2.3"
2.2.0 :004 > c = MongoClient.new
NameError: uninitialized constant MongoClient
    from (irb):4
    from /Users/me/.rvm/rubies/ruby-2.2.0/bin/irb:11:in `<main>'
2.2.0 :005 >

What's the problem?

The object you want to instantiate is Mongo::Client.new

Docs are here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM