MongoDB数据库之mongod的用法详解

发布时间:2020-01-21编辑:脚本学堂
本文详细介绍了MongoDB数据库中mongod程序的用法,以及mongod在使用中的问题与解决方法,供大家参考学习。

本节是 MongoDB数据库之mongod的用法详解 第三部分的内容,请大家继续阅读。
Mongod 默认会打开一个 HTTP 监听端口,通过浏览器能获取 MongoDB 服务器的相关状态信息。
如果不想启动 HTTP Listening,可以使用 --nohttpinterface 参数。
 

复制代码 代码示例:

$ sudo ./mongod --dbpath /var/mongodb --nohttpinterface

Sun Jul 25 01:46:53 MongoDB starting : pid=2406 port=27017 dbpath=/var/mongodb 64-bit

** NOTE: This is a development version (1.5.4) of MongoDB.
** Not recommended for production.

Sun Jul 25 01:46:53 db version v1.5.4, pdfile version 4.5
Sun Jul 25 01:46:53 git version: 6c1361df41d9cabf9026364427a7df44b3c304fd
Sun Jul 25 01:46:53 sys info: Linux domU-12-31-39-06-79-A1 2.6.21.7-2.ec2.v1.2.fc8xen #1 ...
[initandlisten] Sun Jul 25 01:46:53 waiting for connections on port 27017

^C

Sun Jul 25 01:47:19 got kill or ctrl c signal 2 (Interrupt), will terminate after current cmd ends
[interruptThread] Sun Jul 25 01:47:19 now exiting
Sun Jul 25 01:47:19 dbexit:
[interruptThread] Sun Jul 25 01:47:19 shutdown: going to close listening sockets...
[interruptThread] Sun Jul 25 01:47:19 going to close listening socket: 5
[interruptThread] Sun Jul 25 01:47:19 going to close listening socket: 6
[interruptThread] Sun Jul 25 01:47:19 shutdown: going to flush oplog...
[interruptThread] Sun Jul 25 01:47:19 shutdown: going to close sockets...
[interruptThread] Sun Jul 25 01:47:19 shutdown: waiting for fs preallocator...
[interruptThread] Sun Jul 25 01:47:19 shutdown: closing all files...
Sun Jul 25 01:47:19 closeAllFiles() finished
[interruptThread] Sun Jul 25 01:47:19 shutdown: removing fs lock...
Sun Jul 25 01:47:19 dbexit: really exiting now

除了用浏览器查看状态信息外,还可以使用 --rest 参数打开 RESTful 操作。
 

复制代码 代码示例:

$ sudo ./mongod --dbpath /var/mongodb --rest --fork --logpath /dev/null
forked process: 2451
all output going to: /dev/null

$ curl http://localhost:28017/serverStatus?text
{ "version" : "1.5.4",
"uptime" : 13,
"uptimeEstimate" : 0,
"localTime" : Date( "Thu May 24 14:12:39 4253" ),
"globalLock" : { "totalTime" : 13207178,"lockTime" : 400,
"ratio" : 3.028656083835623e-05 },
"mem" : { "bits" : 64,
"resident" : 2,
"virtual" : 67,
"supported" : true,
"mapped" : 0 },
"connections" : { "current" : 0,
"available" : 20000 },
"extra_info" : { "note" : "fields vary by platform",
"heap_usage_bytes" : 158000,
"page_faults" : 0 },
"indexCounters" : { "btree" : { "accesses" : 0,
"hits" : 0,
"misses" : 0,
"resets" : 0,
"missRatio" : 0 } },
"backgroundFlushing" : { "flushes" : 0,
"total_ms" : 0,
"average_ms" : 0,
"last_ms" : 0,
"last_finished" : Date( 0 ) },
"opcounters" : { "insert" : 0,
"query" : 1,
"update" : 0,
"delete" : 0,
"getmore" : 0,
"command" : 0 },
"asserts" : { "regular" : 0,
"warning" : 0,
"msg" : 0,
"user" : 0,
"rollovers" : 0 } }

$ curl http://localhost:28017/blog/users/
{
"offset" : 0,
"rows": [
{ "_id" : { "$oid" : "4c4b2998a09020a0e7681e53" }, "name" : "user0" } ,
{ "_id" : { "$oid" : "4c4b2998a09020a0e7681e54" }, "name" : "user1" } ,
{ "_id" : { "$oid" : "4c4b2998a09020a0e7681e55" }, "name" : "user2" } ,
{ "_id" : { "$oid" : "4c4b2998a09020a0e7681e56" }, "name" : "user3" } ,
{ "_id" : { "$oid" : "4c4b2998a09020a0e7681e57" }, "name" : "user4" } ,
{ "_id" : { "$oid" : "4c4b2998a09020a0e7681e58" }, "name" : "user5" } ,
{ "_id" : { "$oid" : "4c4b2998a09020a0e7681e59" }, "name" : "user6" } ,
{ "_id" : { "$oid" : "4c4b2998a09020a0e7681e5a" }, "name" : "user7" } ,
{ "_id" : { "$oid" : "4c4b2998a09020a0e7681e5b" }, "name" : "user8" } ,
{ "_id" : { "$oid" : "4c4b2998a09020a0e7681e5c" }, "name" : "user9" }
],

"total_rows" : 10 ,
"query" : {} ,
"millis" : 0
}