在Mongo中创建数据库:无法连接,显示“连接失败" [英] Creating a database in Mongo: can't connect, get "connect failed"

查看:87
本文介绍了在Mongo中创建数据库:无法连接,显示“连接失败"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Mongo中创建一个新数据库.但是,我在连接时遇到了问题:

I want to create a new database in Mongo. However, I'm having trouble connecting:

:~$ mongo
MongoDB shell version: 1.6.5
connecting to: test
Tue Dec 21 18:16:25 Error: couldn't connect to server 127.0.0.1 (anon):1154
exception: connect failed

如何连接到mongo以创建新数据库?另外,我可以从命令行创建一个新数据库吗?

How can I connect to mongo in order to create a new database? Alternatively, can I create a new database from the command line?

令人惊讶的是, Mongo文档似乎没有涵盖如何创建数据库.

Slightly surprisingly, the Mongo docs don't seem to cover how to create a database.

谢谢.

推荐答案

要打开Mongo JavaScript shell,应首先初始化一个监听器.

In order to open Mongo JavaScript shell, a Listener should be initialized first.

因此,先运行mongod.exe,然后再运行mongo.exe.两者都在同一位置(/bin).

So, first run mongod.exe before running mongo.exe. Both are in the same location(/bin).

在mongodb中没有单独的命令来创建数据库.只需输入"use dbname;"即可.在控制台中.现在,您已经创建了一个名为"dbname"的数据库.现在,如果您键入显示数据库",您将看不到您刚刚创建的数据库名称.因为mongo不会创建任何数据库,所以您可以创建collection并将文档插入该collection.

There is no separate commands to create a db in mongodb. Just type "use dbname;" in console. Now you have created a db of the name 'dbname'. Now, if you type 'show databases' you cannot see the db name you just created. Because, mongo will not create any db, util you create collection and insert a document into that collection.

希望这对您有用!

这篇关于在Mongo中创建数据库:无法连接,显示“连接失败"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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