连接到特定数据存储Mongo



如何使用mongo交互式shell连接到数据库?我不想连接到默认路径(/data/db)。

发现mongo连接到默认端口和主机(源)上的数据库:

默认情况下,mongo会查找监听端口27017的数据库服务器在localhost接口上。

因此,您应该首先使用所需的数据库位置运行mongod守护进程(服务):

mongod --dbpath ~/some/path/to/desired/db/directory

现在守护进程正在运行,运行mongo连接到它:

$ mongo
MongoDB shell version: 2.6.4
connecting to: test
Server has startup warnings: 
2014-09-01T20:24:44.335-0700 ** WARNING: --rest is specified without --httpinterface,
2014-09-01T20:24:44.335-0700 **          enabling http interface
2014-09-01T20:24:44.348-0700 [initandlisten] 
2014-09-01T20:24:44.348-0700 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
>

键入show dbs查看数据存储中可用的所有数据库:

> show dbs
admin  (empty)
feeds  0.078GB
local  0.078GB
test   (empty)
>

use <db name>切换到使用一个:

> use local
switched to db local
> 

最新更新