无法连接到mongodb [英] Cannot connect to mongodb

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

问题描述

所以我已经使用home brew安装了mongo并且我已经通过npm安装了它,所以我有JS驱动程序.

So I've installed mongo using home brew and I've installed it through npm, so I have the JS driver.

当我在命令行中运行 mongo 时,我得到了这个 -

When I run mongo in command line though, I get this -

 MongoDB shell version: 2.2.2
connecting to: test
Thu Jan 24 02:38:26 Error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js:91
exception: connect failed

为什么会这样?

推荐答案

安装 MongoDB 后,打开终端窗口并转到存储 MongoDB 应用程序的文件路径,例如 c:\MongoDB.然后输入 mongod 并按回车键.这应该开始运行这个进程.Mongod 是您随后通过 mongo shell 访问的数据库服务器.

After you've installed MongoDB, open a terminal window and go to the file path where your MongoDB application is stored e.g c:\MongoDB. Then type mongod and hit enter. This should start this process running. Mongod is the database server that you then access via the mongo shell.

mongod 运行后,打开一个新的终端窗口并输入 mongo 然后回车.您现在应该已经启动并运行了.作为示例,您可以通过在 mongo shell 中键入以下内容来测试它是否正常工作:

After mongod is running, open a new terminal window and type mongo then hit enter. You should now be up and running. You can test that it's working by typing the following into the mongo shell as an example:

>
>db.names.save({'name':"James"})
>db.names.find()

这应该会返回您刚刚保存到数据库中的文档,如下例所示.

This should then return the document you have just saved to the database as shown in the example below.

>{"_id" ObjectID:"764tdf763dyf6337fd376","name":"James"}

通读文档并在线查找教程.10gen 刚刚开始了优秀的在线课程.它是免费的,从本周开始,所以你可能仍然可以注册.

Read through the documentation and look for tutorials online. 10gen have just started an excellent online course. It's free and started this week so you might still be able to register.

这篇关于无法连接到mongodb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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