mongo-红宝石连接问题 [英] mongo - ruby connection problem

查看:67
本文介绍了mongo-红宝石连接问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了mongo和bson_ext 现在,我创建了一个.rb文件,其中包含以下内容::

I have installed mongo and bson_ext now I have created a .rb file with the following contents ::

require 'rubygems'
require 'mongo'

db = Mongo::Connection.new.db("mydb")
db = Mongo::Connection.new("localhost").db("mydb")
db = Mongo::Connection.new("localhost", 27017).db("mydb")

但是我在运行代码时遇到以下错误

However I am getting following error on running the code

yuzaki@ubuntu:~$ ruby firstruby.rb
/home/ryuzaki/.rvm/gems/ruby-1.9.2-p136/gems/mongo-1.2.0/lib/mongo/connection.rb:451:in `connect': Failed to connect to a master node at localhost:27017 (Mongo::ConnectionFailure)
    from /home/ryuzaki/.rvm/gems/ruby-1.9.2-p136/gems/mongo-1.2.0/lib/mongo/connection.rb:554:in `setup'
    from /home/ryuzaki/.rvm/gems/ruby-1.9.2-p136/gems/mongo-1.2.0/lib/mongo/connection.rb:98:in `initialize'
    from firstruby.rb:4:in `new'
    from firstruby.rb:4:in `<main>'

请帮助!

推荐答案

这肯定是由于您的mongo服务器未运行.由于您使用的是Ubuntu,请尝试执行sudo /etc/init.d/mongodb start,然后查看您的代码是否有效.

This is definitely due to your mongo server not running. Since you're on Ubuntu, try doing a sudo /etc/init.d/mongodb start and then see if your code works.

这篇关于mongo-红宝石连接问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆