10.数据库命令操作 runCommand()

来源:互联网 发布:爱口袋软件下载 编辑:程序博客网 时间:2024/05/27 20:26

1.命令执行器runCommand

1.1用命令执行完成一次删除表的操作

db.runCommand({drop:"map"}) {         "nIndexesWas" : 2,         "msg" : "indexes dropped for collection",         "ns" : "foobar.map",         "ok" : 1 }

2.如何查询mongoDB为我们提供的命令

1.在shell中执行 db.listCommands()
2.访问网址 http://localhost:28017/_commands (需要在mongod服务启动时进行–rest的参数配置)

3.常用命令举例

3.1查询服务器版本号和主机操作系统

db.runCommand({buildInfo:1})     {        "version" : "2.0.4",        "gitVersion" : "329f3c47fe8136c03392c8f0e548506cb21f8ebf",        "sysInfo" : "windows sys.getwindowsversion(major=6, minor=0, build=6002, platform=2, service_pack='Service Pack 2') BOOST_LIB_VERSION=1_42",        "versionArray" : [                2,                0,                4,                0        ],        "bits" : 32,        "debug" : false,        "maxBsonObjectSize" : 16777216,        "ok" : 1}

3.2查询执行集合的详细信息,大小,空间,索引等……

db.runCommand({collStats:"persons"}) {        "ns" : "persons.persons",        "count" : 12,        "size" : 2344,        "avgObjSize" : 195.33333333333334,        "storageSize" : 12288,        "numExtents" : 1,        "nindexes" : 1,        "lastExtentSize" : 12288,        "paddingFactor" : 1,        "flags" : 1,        "totalIndexSize" : 8176,        "indexSizes" : {                "_id_" : 8176        },        "ok" : 1}

3.3查看操作本集合最后一次错误信息

 db.runCommand({getLastError:"persons"}) { "n" : 0, "connectionId" : 1, "err" : null, "ok" : 1 }

显示没有操作错误

0 0
原创粉丝点击