onnectionId" : 7,
"numYields" : 0
}
]
}
>
代码解释:
opid:操作进程号
op: 操作类型(query ,update ,etc)
ns: 命名空间(namespace),操作对象
query :显示操作的具体内容
lockType: 锁的类型,指明是写锁还是读锁
结束进程
> db.killOp(630385)
{ "info" : "attempting to kill op" }
我们查看下:
> db.currentOp()
{ "inprog" : [ ] }
>
监控系统的状态和性能
使用serverStatus命令可以获取到运行中的MongoDB服务器统计信息,下面我们来执行命令,查看MongoDB服务器的统计信息(不同平台或不同版本的键会有所不同),代码如下:
> db.runCommand({"serverStatus":1})
{
"host" : "lindenpatservermongodb01",
"version" : "2.0.2",
"process" : "mongod",
"uptime" : 6003,
"uptimeEstimate" : 5926,
"localTime" : ISODate("2012-04-15T11:02:21.795Z"),
"globalLock" : {
"totalTime" : 6002811172,
"lockTime" : 24867,
"ratio" : 0.000004142559092311891,
"currentQueue" : {
"total" : 0,
"readers" : 0,
"writers" : 0
},
"activeClients" : {
"total" : 0,
"readers" : 0,
"writers" : 0
}
},
"mem" : {
"bits" : 64,
"resident" : 52,
"virtual" : 1175,
"supported" : true,
"mapped" : 160,
"mappedWithJournal" : 320
},
"connections" : {
"current" : 1,
"available" : 818
},
"extra_info" : {
"note" : "fields vary by platform",
"heap_usage_bytes" : 341808,
"page_faults" : 14
},
"indexCounters" : {
"btree" : {
"accesses" : 1,
"hits" : 1,
"misses" : 0,
"resets" : 0,
"missRatio" : 0
}
},
"backgroundFlushing" : {
"flushes" : 100,
"total_ms" : 13,
"average_ms" : 0.13,
"last_ms" : 1,
"last_finished" : ISODate("2012-04-15T11:02:19.010Z")
},
"cursors" : {
"totalOpen" : 0,
"clientCursors_size" : 0,
"timedOut" : 0
},
"network" : {
"bytesIn" : 1729666458,
"bytesOut" : 1349989344,
"numRequests" : 21093517
},
"opcounters" : {
"insert" : 5,
"query" : 8,
"update" : 0,
"delete" : 0,
"getmore" : 0,
"command" : 21093463
},
"asserts" : {
"regular" : 0,
"warning" : 0,
"msg" : 0,
"user" : 0,
"rollovers" : 0
},
"writeBacksQueued" : false,
"dur" : {
"commits" : 30,
"journaledMB" : 0,
"writeToDataFilesMB" : 0,
"compression" : 0,
"commitsInWriteLock" : 0,
"earlyCommits" : 0,
"timeMs" : {
"dt" : 3073,
"prepLogBuffer" : 0,
"writeToJournal" : 0,
"writeToDataFiles" : 0,
"remapPrivateView" : 0
}
},
"ok" : 1
}
>
数据导出与导入 mongoexport和mongoinport
使用mongoexport导出数据
先看数据:
> db.t1.find()
{ "_id" : ObjectId("4f8ac746b2764d3c3e2cafbb"), "num" : 1 }
{ "_id" : ObjectId("4f8ac74cb2764d3c3e2cafbc"), "num" : 2 }
{ "_id" : ObjectId("4f8ac74eb2764d3c3e2cafbd"), "num" : 3 }
{ "_id" : ObjectId("4f8ac751b2764d3c3e2cafbe"), "num" : 4 }
{ "_id" : ObjectId("4f8ac755b2764d3c3e2cafbf"), "num" : 5 }
>
使用代码:
./mongoexport.exe -d test -c t1 -o t1.dat
connected to: 127.0.0.1
exported 5 records
[root@mongodb01 /home/mongo/mongodb-2.0.2/bin]$ ls
bsondump mongodump mongoimport mongosniff t1_count.js
mongo mongoexport mongorestore mongostat t1.dat
mongod mongofiles mongos mongotop testfiles.txt
[root@mongodb01 /home/mongo/mongodb-2.0.2/bin]$ cat t1.dat
{ "_id" : ObjectId("4f8ac746b2764d3c3e2cafbb"), "num" : 1 }
{ "_id" : ObjectId("4f8ac74cb2764d3c3e2cafbc"), "num" : 2 }
{ "_id" : ObjectId("4f8ac74eb2764d3c3e2cafbd"), "num" : 3 }
{ "_id" : ObjectId("4f8ac751b2764d3c3e2cafbe"), "num" : 4 }
{ "_id" : ObjectId("4f8ac755b2764d3c3e2cafbf"), "num" : 5 }
./mongoexport.exe -d test -c t1 -o t1.dat 使用参数说明
-d: 指明使用的数据库
-c: 指明导出的集合,这里是t1
-o: 导出的数据名,这里的数据名默认使用相对路径,也可以使用绝对路径。
导出的数据格式的