如何使用mongo
交互式shell连接到数据库?我不想连接到默认路径(/data/db
)。
答案 0 :(得分:1)
结果mongo
连接到默认端口和主机(source)上的数据库:
默认情况下,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
>