[plain] view plaincopy
mongo -u admin -p admin 1921680197:27017/pagedb
通过mongo实现连接,可以非常灵活的选择参数选项,参看命令帮助,如下所示:
[plain] view plaincopy
mongo --help
MongoDB shell version: 183
usage: mongo [options] [db address] [file names (ending in js)]
db address can be:
foo foo database on local machine
19216905/foo foo database on 19216805 machine
19216905:9999/foo foo database on 19216805 machine on port 9999
options:
--shell run the shell after executing files
--nodb don't connect to mongod on startup - no 'db address'
arg expected
--quiet be less chatty
--port arg port to connect to
--host arg server to connect to
--eval arg evaluate javascript
-u [ --username ] arg username for authentication
-p [ --password ] arg password for authentication
-h [ --help ] show this usage information
--version show version information
--verbose increase verbosity
--ipv6 enable IPv6 support (disabled by default)
2、基于MongoDB支持的javascript实现远程连接
当你已经连接到一个远程的MongoDB数据库服务器(例如,通过mongo连接到1921680184),现在想要在这个会话中连接另一个远程的数据库服务器(1921680197),可以执行如下命令:
[plain] view plaincopy
> var x = new Mongo('1921680197:27017')
> var ydb = xgetDB('pagedb');
> use ydb
switched to db ydb
> db
ydb
> ydbpagefindOne()
{
"_id" : ObjectId("4eded6a5bf3bfa0014000003"),
"content" : "巴黎是浪漫的城市,可是",
"pubdate" : "2006-03-19",
"title" : "巴黎:从布鲁塞尔赶到巴黎",
"url" : ">
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)